EleKtr1X
EleKtr1X

Reputation: 41

discord.js - Bot sending messages twice

My discord bot keeps sending messages twice, as shown in this image.

Here's the simplified code for 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);

I even tried changing the token multiple times and I killed the terminal to get rid of multiple instances, but nothing prevailed. What can I do to fix this?

Upvotes: 1

Views: 9598

Answers (4)

aizakkusnail
aizakkusnail

Reputation: 9

The only thing I did was close and re-open the text editor.

Upvotes: 0

EleKtr1X
EleKtr1X

Reputation: 41

I actually figured out what was happening here, it was an issue with pm2.

Long story short, don't run pm2 and node . at the same time, that was what caused this issue.

Upvotes: 0

opc
opc

Reputation: 136

This has happened to me before. How I fixed it is to regenerate the discord token. There was 2 things happening in the background.

Upvotes: 6

dxxta
dxxta

Reputation: 119

If this still happens after to regenerating the token, try using client.destroy() on the code, or killing the exiting process by using cmd+Z in your terminal.

If it is still happening after that, just restart your computer. The most likely issue is that your application has runs twice behind.

here is my terminal log

Upvotes: 1

Related Questions