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?
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;)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.