【发布时间】:2021-07-26 05:44:09
【问题描述】:
当我在命令名称中包含空格时,这些命令将不会运行。我正在使用命令处理程序,在我的 index.js 文件中,我们有:
client.on('message', msg => {
if (!msg.content.startsWith(prefix) || msg.author.bot) return;
const args = msg.content.slice(prefix.length).trim().split(/ +/g);
const commandName = args.shift().toLowerCase();
const command = client.commands.get(commandName)
|| client.commands.find(cmd => cmd.aliases && cmd.aliases.includes(commandName));
if (!command) return;
try {
command.execute(msg, args);
} catch (error) {
console.error(error);
msg.reply("I'm encountering an error trying to execute that command. Please try again.");
}
});
在我的command.js 文件中,我们有:
module.exports = {
name: 'command name',
execute(msg, args) {
msg.channel.send("command");
},
};
当我将command name 更改为command-name 或commandname 时,它可以工作!但是当它是command name 时,我的机器人没有输出任何响应......甚至没有错误消息。我哪里错了?是否有一些我忽略的简单解决方案或解决方法?提前致谢。
【问题讨论】:
标签: discord discord.js bots