Javascript 不和谐机器人。JS无法读取属性';执行';未定义的

Javascript 不和谐机器人。JS无法读取属性';执行';未定义的,javascript,node.js,discord,Javascript,Node.js,Discord,我不能让它工作。这是我的主要文件: 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(./co

我不能让它工作。这是我的主要文件:

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:

我得到这个错误:

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

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

在你的出口声明中似乎有点输入错误。您忘记定义执行键了。应该是这样的:

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

你的出口声明好像有点输入错误。您忘记定义执行键了。应该是这样的:

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