[英]How do I get my discord bot react to it being mentioned?
I'm trying to get my JavaScript Discord bot to react to being mentioned in discord.我试图让我的 JavaScript Discord 机器人对 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 语句就足够了:
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.也因为用户提及在 PC 和移动设备上不一样。
Happy coding;)快乐编码;)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.