Discord.js-Discord机器人停止响应命令

我试图向我的机器人添加一些新功能,但它最终没有工作,所以我删除了新代码,现在它不会响应任何命令。它仍然在线,但正如我之前所说,它完全没有响应。我已经查看了代码,但找不到问题。我对编码机器人还是个新手,所以我可能遗漏了一些东西。这是我的主要文件代码:

const fs = require('fs');
const Discord = require('discord.js');
const { prefix, token } = require('./config.json');

const client = new Discord.Client();
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('Ready!');
});

client.on('message', message => {
console.log(message)
    if (!message.content.startsWith(prefix) || message.author.bot) return;

    const args = message.content.slice(prefix.length).trim().split(/ +/);
    const command = args.shift().toLowerCase();


    if (!client.commands.has(command)) return;

    try {
        client.commands.get(command).execute(message, args);
    } catch (error) {
        console.error(error);
        message.reply('there was an error trying to execute that command!');
    }
});

client.login(token);

这是一个命令文件:

    function pickOneFrom(array) {
    return array[Math.floor(Math.random() * array.length)];
  }
  
  module.exports = {
    name: 'throw',
    description: 'this is a throw command!',
    execute(message, args) {
      const responses = ['a apple', 'a melon', 'a potato', 'a snowball', 'a spanner', 'a computer'];
  
      message.channel.send(
        `${message.author} threw ${pickOneFrom(responses)} at ${
          message.mentions.users.first() ?? 'everyone'
        }!`,
      );
    },
  };```

以上是Discord.js-Discord机器人停止响应命令的全部内容。
THE END
分享
二维码
< <上一篇
下一篇>>