discord.js-Bot发送消息两次

时间:2020-02-29 16:34:45

标签: discord.js

我的不和谐机器人不断发送两次消息,如this image所示。

这是index.js的简化代码:

const { prefix, token, giphyToken } = require('./config.json');
const fs = require('fs')
const Discord = require('discord.js');
const client = new Discord.Client();
client.commands = new Discord.Collection();
const commandFiles = fs.readdirSync('./commands').filter(file => file.endsWith('.js'));

var GphApiClient = require('giphy-js-sdk-core')
giphy = GphApiClient(giphyToken)

client.once('ready', () => {
    console.log('Ready!');

});


for (const file of commandFiles) {
    const command = require(`./commands/${file}`);
    client.commands.set(command.name, command);
}

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

我什至尝试多次更改令牌,并且杀死了终端以摆脱多个实例,但没有成功。 我该怎么做才能解决此问题?

4 个答案:

答案 0 :(得分:0)

如果在重新生成令牌后仍然出现这种情况,请尝试在代码上使用client.destroy(),或者在终端中使用cmd+Z终止退出过程。

如果此后 still 仍在发生,只需重新启动计算机即可。最可能的问题是您的应用程序落后了两次。

here is my terminal log

答案 1 :(得分:0)

这以前发生在我身上。我如何修复它是重新生成不和谐令牌。后台发生了两件事。

答案 2 :(得分:0)

我实际上知道这里发生了什么,这是pm2的问题。

长话短说,不要同时运行pm2和node .,这就是导致此问题的原因。

答案 3 :(得分:0)

我唯一要做的就是关闭并重新打开文本编辑器。