如何检测机器人是否已被提及? [英] How to detect if the bot has been mentioned?

查看:68
本文介绍了如何检测机器人是否已被提及?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何检测是否提到了我的机器人?

How can I detect if my bot is mentioned?

到目前为止,我已经尝试过这些操作:

I tried these thus far:

if (msg.content.toLowerCase().includes('@The Guardian of The Bar#5180')) {
  msg.channel.send("My prefix here is" + prefix + "\n You can start with ``" + prefix + "help``");
}

if (msg.content.toLowerCase().includes('@The Guardian of The Bar')) {
  msg.channel.send("My prefix here is" + prefix + "\n You can start with ``" + prefix + "help``");
}

if (msg.content.includes('@The Guardian of The Bar#5180')) {
  msg.channel.send("My prefix here is" + prefix + "\n You can start with ``" + prefix + "help``");
}

if (msg.content.includes('@The Guardian of The Bar#5180')) {
  msg.channel.send("My prefix here is" + prefix + "\n You can start with ``" + prefix + "help``");
}


推荐答案

我没有经验discord.js,但根据在文档中,消息对象的方法为 message.isMemberMentioned(User或GuildMember)。使用此方法,可以使用

I'm not experienced in discord.js, but according to this in the documentation, a message object has a method message.isMemberMentioned(User or GuildMember). Using this method, one can use

client.on('message', message => { //this event is fired, whenever the bot sees a new message
   if (message.isMemberMentioned(client.user)) { //we check, whether the bot is mentioned, client.user returns the user that the client is logged in as
      //this is where you put what you want to do now
   }
});

我想建议您阅读文档完全,然后再尝试制作机器人。

I would like to recommend, that you read the documentation fully, before you try to make a bot.

在v12 discord.js上,您现在必须使用 message.mentions.has(bot.user)

On v12 discord.js you now have to use message.mentions.has(bot.user)

这篇关于如何检测机器人是否已被提及?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆