1

The goal :

I am trying to get the bot to send a message when a specific user is pinged in a message.
So I tried with this :

if (message.mentions.has(bot.users.cache.get(userID)))

And it's working fine, if you ping the user, the bot sends a message. Excepted...

The problem :

The bot also react when you simply reply to the user without pinging the user in the message, and I don't want that.
The only way I can see is :

if (message.content.includes(userID))
Ninluc
  • 23
  • 1
  • 6

1 Answers1

2

You should check directly if they were pinged in the message.

const userRegex = new RegExp(`<@!?${userID}>`)
if (message.content.match(userRegex)) {
  //user has been mentioned and it was not because of reply
}
MrMythical
  • 8,908
  • 2
  • 17
  • 45