迪克机器人。JS 无法读取未定义的属性“执行”

我无法让它工作。这是我的主文件:


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);

和我的文件平.js:


module.exports = {

  name: 'test',

  description: "Tester ting",

  execute(message, args) {

    message.channel.send("STOR TEST")

  }

}

我收到此错误:


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

我试图让我的机器人来拯救我:-)


慕森卡
浏览 102回答 1
1回答

慕丝7291255

您的出口声明中似乎有点拼写错误。您忘记定义执行键。它应该看起来像这样:module.exports = {  name: 'test',  description: "Tester ting",  execute: function(message, args) {    message.channel.send("STOR TEST")  }}
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

JavaScript