How to detect if the bot has been mentioned?(如何检测是否提到了机器人?)
问题描述
如何检测我的机器人是否被提及?
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 + "
You can start with ``" + prefix + "help``");
}
if (msg.content.toLowerCase().includes('@The Guardian of The Bar')) {
msg.channel.send("My prefix here is" + prefix + "
You can start with ``" + prefix + "help``");
}
if (msg.content.includes('@The Guardian of The Bar#5180')) {
msg.channel.send("My prefix here is" + prefix + "
You can start with ``" + prefix + "help``");
}
if (msg.content.includes('@The Guardian of The Bar#5180')) {
msg.channel.send("My prefix here is" + prefix + "
You can start with ``" + prefix + "help``");
}
推荐答案
我对discord.js没有经验,但是根据this 在文档中,消息对象有一个方法 message.isMemberMemberMember(User or 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)
这篇关于如何检测是否提到了机器人?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何检测是否提到了机器人?
基础教程推荐
- WatchKit 支持 html 吗?有没有像 UIWebview 这样的控制器? 2022-01-01
- Javascript 在多个元素上单击事件侦听器并获取目标 2022-01-01
- jQuery File Upload - 如何识别所有文件何时上传 2022-01-01
- 如何使用sencha Touch2在单页中显示列表和其他标签 2022-01-01
- 每次设置弹出窗口的焦点 2022-01-01
- 为什么我在 Vue.js 中得到 ERR_CONNECTION_TIMED_OUT? 2022-01-01
- 如何在特定日期之前获取消息? 2022-01-01
- 什么是不使用 jQuery 的经验技术原因? 2022-01-01
- 如何使用 CSS 显示和隐藏 div? 2022-01-01
- Node.js 有没有好的索引/搜索引擎? 2022-01-01
