Velvet Star Monitor

Standout celebrity highlights with iconic style.

updates

discord.js - Bot sending messages twice

Writer Matthew Barrera

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?

2

4 Answers

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

1

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

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.

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

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.