Reputation: 77
I'm trying to get my JavaScript Discord bot to react to being mentioned in discord. However, it doesn't do anything when someone mentions it.
const Discord = require('discord.js');
const keepAlive = require('./server');
const client = new Discord.Client();
client.on('message', message => {
if (message.toString().toLowerCase().includes('@class of 2020 assistant')) {
message.author.send('Your assistance ticket haassistancese wait for a DM from ageekdude.');
const ageekdude = client.users.cache.get('571713056673890324');
if (ageekdude) ageekdude.send(`${message.author} has requested an assistance ticket.`)
}
});
keepAlive();
client.login(process.env.TOKEN);
Could someone please give me a suggestion on how I get the bot to react to it being mentioned?
Upvotes: 1
Views: 1285
Reputation: 1464
To make your bot react to it being mentionned, this if statement should be enough :
if (/<@!YourBotID>|<@YourBotID>/.test(message.content)) {
return message.reply('hey, you mentioned me !');
}
You'll need to use the !
as well because user mentions are not the same on PC and mobile.
Happy coding ;)
Upvotes: 2