问题
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``");
}
回答1:
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.
来源:https://stackoverflow.com/questions/55195128/how-to-detect-if-the-bot-has-been-mentioned