I'm trying to make my discord.js bot send messages when someone pings me. How can I do that??
I was trying with that code:
if(message.content === "<@723821826291138611>") {
message.channel.send("Hello, sup? ")
}
but that doesn't work. how can I do that?
CodePudding user response:
You have to use if(message.content.includes("<@723821826291138611>"))
instead of if(message.content === "<@723821826291138611>")
to make it work!
But also you can use this code to do it:
let mentioned = message.mentions.members.first();
if(mentioned && mentioned.id == "723821826291138611") {
message.channel.send("YOUR_TEXT")
}
CodePudding user response:
While the accepted answer works, the best - and most conventional - way to do this is to check the MessageMentions#(users|members) collection.
if (message.mentions.users.has("723821826291138611")) {
// Your code
}
This will return true if the mentioned is found in any order not only first, it's possible for the API to emit the mentions in different orders if multiple mentions were given. I wouldn't recommend searching the content string either.