我运行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
答案 0 :(得分:1)
所以我认为这可能是拼写错误和目录结构的组合。尝试进行以下更改:
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);