我的 Discord 机器人多次回复一个命令,我想知道是否有办法只发送一次



当我发出命令时,我的discord bot将多次响应,而不是一次。我正在使用JavaScript,找不到任何方法让它发挥作用。

这是我的主要脚本的一部分:

const Discord = require('discord.js');
const client = new Discord.Client();
const fs = require("fs");

const prefix = '-';

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.categories = fs.readdirSync("./commands/");
client.once('ready', () => {
console.log('Bot 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);
}
}

这是我的命令ping的子文件夹:

module.exports = {
name: 'ping',
description: "this is a ping command!",
execute(message, args){
message.channel.send('pong!')
}
}

感谢您帮助

目前也在写一个,我没有发现任何问题,你的节点可能运行了两次吗?

最新更新