Ad

DiscortJS Bot Send A Message Back On The Channel Mentioning A Specific User

I have build this message on js. And i want to add a condition if you tag an user the bot to add the message + tag that person otherwise just to send a normal message.

The issue that I have is what is the right variable for user_mention. I found different ways, but couldn't make it to work.

DiscordClient.on('message', message => {
  const msg = message.content.toLowerCase();
  const mention = message.mentions.users;

  if (msg === "yubnub") {
    if (mention == null){
      message.channel.send('YUB NUB!! YUB NUB!! Grrrrr!!');
    } else {
      message.channel.send('YUB NUB!! YUB NUB!! Grrrrr!! ' + ${@user_mention})
    }
  }

});
Ad

Answer

I think mention is an array of users. So you can do:

for (const user of mention) {
    message.channel.send('YUB NUB!! YUB NUB!! Grrrrr!! @' + user.username)
}
Ad
source: stackoverflow.com
Ad