I’m having trouble with my Discord bot because it keeps posting the same response multiple times when users run commands. This started happening recently and I can’t figure out what’s causing it. I’ve tried restarting both my code and the bot but the problem persists.
Here’s my main bot file:
const Discord = require('discord.js');
const fs = require('fs');
const bot = new Discord.Client();
const commandPrefix = '!';
bot.commands = new Discord.Collection();
const cmdFiles = fs.readdirSync('./handlers/').filter(file => file.endsWith('.js'));
for (const file of cmdFiles){
const cmd = require(`./handlers/${file}`);
bot.commands.set(cmd.name, cmd);
}
bot.once('ready', () => {
console.log('Bot is running');
});
bot.on('message', msg =>{
if(!msg.content.startsWith(commandPrefix) || msg.author.bot) return;
const arguments = msg.content.slice(commandPrefix.length).split(/ +/);
const cmd = arguments.shift().toLowerCase();
if(cmd === 'channel'){
bot.commands.get('channel').execute(msg, arguments);
} else if (cmd == 'social'){
msg.channel.send('https://twitter.com/example');
}
});
And here’s my command handler file (channel.js):
module.exports = {
name: 'channel',
description: "shows our main channel",
execute(msg, arguments){
msg.channel.send('https://youtube.com/example?sub_confirmation=1');
}
}
Any ideas what might be causing the duplicate messages?