【问题标题】:My Discord bot reponds multiple time to one command and I want to know if there's a way to send it only once我的 Discord 机器人多次响应一个命令,我想知道是否有办法只发送一次
【发布时间】: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


    【解决方案1】:

    目前也在写一个,我看不出有什么问题,你的节点有可能运行了两次吗?

    【讨论】:

    • 如何检查它是否运行了两次? (对不起,我是初学者)
    • 重启你的电脑,以防万一有多个实例。
    猜你喜欢
    • 2020-04-02
    • 2022-10-24
    • 2019-08-25
    • 2022-12-15
    • 2021-04-19
    • 2017-10-02
    • 2020-11-07
    • 2021-11-29
    • 2020-07-08
    相关资源
    最近更新 更多