简体   繁体   English

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

[英]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.

相关问题 如何让我的机器人等待提到的用户 discord.js 的回复? - How do I get my bot to wait for reply from a mentioned user discord.js? 当提到它时,如何让我的 Discord 机器人识别它? - How can I make my Discord bot recognize it when it is mentioned? 如何让我的 Discord 机器人发送欢迎消息? - How do I get my Discord bot to send a welcome message? 如果提到机器人,我如何让我的命令返回? - How do i make my command return if a bot is mentioned? Discord.js 如何让机器人对它刚刚通过 id 在 discord 中发送的消息做出反应? - Discord.js How do I get the bot to react to the message it just sent in discord by id? 当提到特定用户时,如何让不和谐机器人发送消息? - How do i make a discord bot send a message when a specific user is mentioned? 如何检测到提到的成员并使用不和谐的bot为其分配角色? (JavaScript)的 - How do I detect a mentioned member and assign a role to them with a discord bot? (Javascript) 如何制作 DM 提到的用户的 discord js 机器人? - How do I make a discord js bot that DM's a mentioned user? 如何使用 java 脚本让 discord 机器人向命令中提到的人发送 DM? - How do I make a discord bot send a DM to someone mentioned in the command, using java script? 如何让我的 discord 机器人删除我的消息并对上面的消息作出反应? - How do I make my discord bot delete my message and react to the message above?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM