Reputation: 5
That's weird, but for some reason my bot works with different prefixes. I mean, at the very beggining for the code I set my prefix as "-". But the bot's commands also execute when typing "_, >, ? etc." Note that I'm using a command handler in my code so that could be an issue. Here's the full code:
const Discord = require('discord.js');
const { Client, Collection } = require ('discord.js');
const client = new Discord.Client();
const token = 'TOKEN';
const PREFIX = '-';
const fs = require('fs');
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.on('ready', () =>{
console.log('Compass is online');
client.user.setActivity('GameCore', {type: 'WATCHING'}).catch(console.error);
})
client.on('message', message=>{
let args = message.content.substring(PREFIX.length).split(" ")
switch(args[0]){
case 'help':
client.commands.get('help').execute(message, args);
break;
case 'kick':
client.commands.get('kick').execute(message, args);
}
})
client.login(token);
If you need any other information feel free to tell me.
Any help would be appreciated. Thanks!
Upvotes: 0
Views: 98
Reputation: 140
Add an if (!message.content.startsWith(PREFIX)) return;
to the start of your message event.
Upvotes: 1