当我运行node index.js时,我的节点应用程序不运行
以下是我拥有的文件:
文件index.js:
const command = require('discord.js-commando')
const bot = new commando.Client();
bot.registery.registerGroup('random', 'Random');
bot.register.registerDefaults();
bot.registery.regusterCommandsIn(__dirname + "/commands")
bot.login('zzzzz');和文件random.js:
const commando = require('discord.js-commando')
class DiceRollCommand extends commando.Command {
constructor(client) {
super(client, {
name: 'roll',
group: 'random',
memberName: 'roll',
description: 'Rolls a die'
});
}
async run(message, args) {
var roll = Math.floor(Math.random() * 6) + 1;
message.reply("You rolled a die") + roll);
}
}
module.exports = DiceRollCommand;这是错误的堆栈跟踪:
Error: Cannot find module 'C:\Users\dange\Desktop\bots\js\commands\random'
at Function.Module._resolveFilename (module.js:538:15)
at Function.Module._load (module.js:468:25)
at Function.Module.runMain (module.js:684:10)
at startup (bootstrap_node.js:187:16)
at bootstrap_node.js:608:3发布于 2018-03-04 07:38:27
所以我认为这可能是拼写错误和目录结构的组合。尝试进行以下更改:
const commando = require('discord.js-commando')
const bot = new commando.Client();
// Typo in the following: should be, bot.registry
bot.registry.registerGroup('random', 'Random');
bot.registry.registerDefaults();
// Typo Here: should be, registerCommandsIn
bot.registry.registerCommandsIn(__dirname + "/commands")
bot.login('zzzzz');您的目录结构应如下所示。registerCommandsIn加载给定目录中的所有命令。
/commands/random.js
/index.js而且,您应该确保在harmony flag and with no less than Node 7.0上运行index.js。
node index.js --harmony另外,在random.js的第17行也找到了这个
message.reply("You rolled a die") + roll);
// I assume you want to send the roll
message.reply("You rolled a die" + roll);https://stackoverflow.com/questions/49090241
复制相似问题