Reputation: 1
When I make a command, my discord bot will respond multiple time instead of once. I'm using JavaScript and can't find any ways to make it work.
Here's my part of my main script:
const Discord = require('discord.js');
const client = new Discord.Client();
const fs = require("fs");
const prefix = '-';
client.commands = new Discord.Collection();
const commandFiles = fs.readdirSync('./commands/').filter(file => file.endsWith('.js'));
for(const file of commandFiles){
const command = require(`./commands/${file}`);
client.commands.set(command.name, command);
}
client.categories = fs.readdirSync("./commands/");
client.once('ready', () => {
console.log('Bot is online!');
});
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(command === 'ping'){
client.commands.get('ping').execute(message, args);
}
}
Here's my subfolder for the command ping:
module.exports = {
name: 'ping',
description: "this is a ping command!",
execute(message, args){
message.channel.send('pong!')
}
}
Thanks for helping
Upvotes: 0
Views: 67
Reputation: 11
Currently writing one too and I dont see anything wrong with this, is it possible your node is running twice?
Upvotes: 1