本文介紹了如何檢測是否提到了機器人?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!
問題描述
如何檢測我的機器人是否被提及?
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)
這篇關于如何檢測是否提到了機器人?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!
【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!