提问者:小点点

不和谐机器人。 JS无法读取未定义的属性“execute”


我不能让它工作。 下面是我的主文件:

const fs = require('fs');
  bot.commands = new Discord.Collection();
  const commandFiles = fs.readdirSync('./commands/').filter(file => file.endsWith('.js'));

  for(const file of commandFiles) {
    const command = require(./commands/${file});
    bot.commands.set(command.name, command);
  }

 if (message.content == 'ping' || message.content == 'Ping') {
   //message.channel.send('Pong');
   bot.commands.get('ping').execute(message);

和我的文件ping.js:

module.exports = {
  name: 'test',
  description: "Tester ting",
  execute(message, args) {
    message.channel.send("STOR TEST")
  }
}

出现以下错误:

UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'execute' of undefined

我试着让我的机器人告诉我:-)


共1个答案

匿名用户

看来你的出口单上有个小错误。 您忘记定义execute键。 应该是这样的:

module.exports = {
  name: 'test',
  description: "Tester ting",
  execute: function(message, args) {
    message.channel.send("STOR TEST")
  }
}