我实际上可以运行机器人,它会让我与其他 3 个命令交互,但是当尝试执行“kickembed”时它会失败并给我错误“client.commands.get('kickembed')。执行(消息,参数,不和谐)” ^ 无法读取未定义的“执行”属性
tbh,我尝试了everithing,我的小脑袋无法解决这个问题,你的时间太糟糕了!
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('Cataclysm is online, beep bop')
});
client.on('message', message =>{
if(!message.content.startsWith(prefix) || message.author.bot) return;
const args = message.content.slice(prefix.length).split(/ +/);
const command = args.shift().toLowerCase();
if(command === 'ping'){
message.channel.send('pong!');
} else if (command === 'welcome'){
client.commands.get('welcome').execute(message, args);
} else if (command === 'ban'){
client.commands.get('Ban').execute(message, args);
} else if (command === 'kick'){
client.commands.get('kick').execute(message, args);
} else if (command === 'kickembed'){
client.commands.get('kickembed').execute(message, args, Discord);
}
}); ~~~
and this is "kickembed"(where i have the problem i think)
~~~ const name = 'kick';
const description = "This command kicks a member!";
function execute(message, args, Discord) {
const banembed = new Discord.MessageEmbed()
.setColor('#ff3838')
.setTitle('A user has been kicked')
.setDescription('player (fix this plis) has been kicked by etc');
message.channel.send(banembed);~~~
答案 0 :(得分:0)
您的 kickembed
文件名称错误,它是 kick
所以它应该是这样的:
const name = 'kickembed';
const description = "This command kicks a member!";
function execute(message, args, Discord) {
const banembed = new Discord.MessageEmbed()
.setColor('#ff3838')
.setTitle('A user has been kicked')
.setDescription('player (fix this plis) has been kicked by etc');
message.channel.send(banembed);