我正在尝试为我的 Discord 服务器制作一个机器人,一切正常,直到我得到第二个命令(哔哔声)。我将进入我的命令提示符类型“node”。它会全部上线,所以我去我的不和谐服务器并输入 ~ping 并且它运行完美。但是当我运行 beep 时,我的命令提示符会显示“TypeError:无法读取未定义的属性‘执行’”。我已经尝试了所有我能在谷歌广告上找到的东西,非常感谢您的帮助!
main.js
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(`Logged in as ${client.user.tag}!`);
client.user.setActivity("Attack On Titan");
});
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'){
client.commands.get('ping').execute(message, args);
} else if (command == 'beep'){
client.commands.get('beep').execute(message, args);
} else if (command == 'server'){
client.commands.get('server').execute(message, args);
}
});
client.login('Super-Secret-Bot-Token');
ping.js
module.exports = {
name: 'ping',
description: 'Ping!',
execute(message) {
message.channel.send('Pong.');
},
};
beep.js
module.exports = {
name: 'Beep',
description: 'It Boops.',
execute(message) {
message.channel.send('Boop!');
},
};