Reputation: 3
I want to be able to make the prefix the name of the bot so I can do like
if(cmd === `${prefix}Hey`) {
const m = await message.channel.send(`Hello`);
}
Where you could use the bot name as prefix "(Bot name) hey" and it would answer hello back since when I try you can only do it without the space like "(bot name)hey" and it would answer hello back. I don't know if that made sense.
Upvotes: 0
Views: 364
Reputation: 144
Possibly something like this in your main file :
const client = new Client(); // Just to represent the bot
client.on('message', (message) => {
const mentionRegex = new RegExp(`^<@!?${client.user.id}>`);
if (mentionRegex.test(message.content) ||
message.content.startsWith(prefix)) {
let cmd;
const words = message.content.split(' ');
if (message.content.startsWith(prefix) {
cmd = words.shift().slice(prefix.length)
} else {
cmd = words.splice(0, 1, '').shift();
}
switch (cmd) {
case 'hey':
message.channel.send('Hello!');
break;
}
}
});
Upvotes: 0