【发布时间】:2021-01-25 02:27:03
【问题描述】:
我正在用一个简单的命令处理程序制作一个不和谐的机器人。我以前从未使用过命令处理程序,所以我对这类函数和类似的东西不太了解。我收到一个错误,说执行未定义,我不知道如何解决。代码:
module.exports = {Discord : 'Discord.JS'}
module.exports = {client : 'Discord.Client'}
const fs = require('fs');
client.commands = new Discord.Collection();
const commandFiles = fs.readdirSync('./commands/').filter(file => file.endsWith('.js'));
for(const file of commandFiles) {
const command = require(`./commands/${file}`);
client.commands.set(command.name, command);
};
client.on('message', msg => {
let message = '';
if (msg.channel === msg.author.dmChannel) {
return
} else {
client.commands.get('./commands/allyApplication').execute(message, msg);
};
if (msg.content.toLowerCase().startsWith('!accept')) {
client.commands.get('./commands/acceptAlly').execute(message, msg);
};
if (msg.content.toLowerCase().startsWith('!decline')) {
client.commands.get('./commands/declineAlly').execute(message, msg);
};
});
这是读取此内容的脚本的代码:
module.exports = {
name: 'declineAlly',
description: 'Declines allies.',
execute(message, msg) {
REST OF CODE
}
}
如果有人知道我该如何解决这个错误,那就太好了,因为我是命令处理程序的新手。
【问题讨论】:
-
你的
set会被称为client.commands.set('declineAlly', command);所以......在你的.get 中,使用declineAlly而不是./commands/declineAlly -
现在错误是找不到模块
标签: javascript node.js discord discord.js