如何修复此问题?我想创建PING命令
错误:client.commands.get('ping'(.run(message,args(^
TypeError:无法读取未定义的属性"get">
这是我的ping代码
module.exports = {
name: 'ping',
description: "this is a ping command!",
execute(message, args){
message.channel.send('pong!');
}
}
这里还有我的index.js
const Discord = require('discord.js');
const client = new Discord.Client();
const prefix = '-';
const fs = require('fs');
client.command = new Discord.Collection();
const commandFiles = fs.readdirSync('./commands/').filter(file => file.endsWith('.js'));
for(const file of commandFiles){
const command = require(`./commands/${file}`);
client.command.set(command.name, command);
}
client.once('ready', () => {
console.log('MuriCraft is online!');
});
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);
}
})
client.login('!Hiden!');
这是一个非常小的命令,因此您可以将其包含在Main/Index.js文件中
if(msg.content === '!ping'){
msg.channel.send('Pong!;)