【发布时间】:2020-12-16 21:55:48
【问题描述】:
当我发出命令时,我的不和谐机器人将响应多次而不是一次。我正在使用 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!')
}
}
感谢您的帮助
【问题讨论】:
标签: javascript node.js command bots discord.js