繁体   English   中英

如何让我的 discord 机器人对提到的它做出反应?

[英]How do I get my discord bot react to it being mentioned?

我试图让我的 JavaScript Discord 机器人对 discord 中的提及做出反应。 但是,当有人提到它时,它不会做任何事情。

 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);

有人可以给我一个建议,告诉我如何让机器人对被提及的它做出反应吗?

为了让你的机器人对被提及的它做出反应,这个 if 语句就足够了:

if (/<@!YourBotID>|<@YourBotID>/.test(message.content)) {
    return message.reply('hey, you mentioned me !');
}

您需要使用! 也因为用户提及在 PC 和移动设备上不一样。
快乐编码;)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM