【发布时间】:2022-02-23 22:43:40
【问题描述】:
每次弹出错误时说 if(command==='clear') referencerError: command is not defined, 尽管 bot 正在上线但没有响应 discord bot 中的任何指令。感谢您的帮助,提前! 我尝试删除 if(command==='clear') 整个部分,但它在下一个播放命令中显示相同的错误,这是音乐机器人的主要命令之一。 我还链接了我用作此代码参考的 youtube 视频,并且我尝试完全按照他所说的对我的不和谐机器人进行编码。 https://www.youtube.com/watch?v=3wJJDM7jUsk&list=RDCMUC08G-UJT58SbkdmcOYyOQVw&index=2
const Discord = require('discord.js');
const client = new Discord.Client();
const prefix = '!';
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.once('ready',() =>{
console.log('Tihadi.io is online!');
} );
client.on('guildMemberAdd', guildMember => {
let welcomeRole = guildMember.guild.roles.cache.find(role => role.name ==='member');
guildMember.roles.add(welcomeRole);
guildMember.guild.channels.cache.get('783308287571132417').send(`Welcome <@$<{guildMember.user.id}> malik, To our server!`)
});
client.on('message', message => {
if (!message.content.startsWith(prefix) || message.author.bot) return;
const args = message.content.slice(prefix.length).split(/ +/);
const commands = args.shift().toLowerCase();
if (command === 'clear') {
client.commands.get('clear').execute(message ,args);
}else if (command==='play') {
client.commands.get('play').execute(message ,args);
}else if (command==='leave') {
client.command.get('leave').execute(messsage ,args);
}
});
client.login('token');
【问题讨论】:
-
这是
commands(const commands = ...) 不是command
标签: javascript node.js discord.js