Pho*_*nix 2 javascript node.js discord.js
如何检测是否提到了我的机器人?
到目前为止,我尝试了这些:
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``");
}
Run Code Online (Sandbox Code Playgroud)
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``");
}
Run Code Online (Sandbox Code Playgroud)
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``");
}
Run Code Online (Sandbox Code Playgroud)
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``");
}
Run Code Online (Sandbox Code Playgroud)
Dex*_*ion 12
我不是在discord.js经验丰富,但根据本文档中,一个消息对象有一个方法message.isMemberMentioned(User or GuildMember)。使用这种方法,可以使用
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
}
});
Run Code Online (Sandbox Code Playgroud)
我想建议您在尝试制作机器人之前完整阅读文档。
在 v12 discord.js 上,您现在必须使用 message.mentions.has(bot.user)
| 归档时间: |
|
| 查看次数: |
12178 次 |
| 最近记录: |