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?
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.