How do I mention a role with Discord.js?

Saatvik K picture Saatvik K · Nov 7, 2019 · Viewed 8.8k times · Source

I am making a bot and I am trying to Ping a certain role. Here is the relevant code:

let msga = msg.author;
msg.channel.send("@NES Found one!! " + msga);

@NES is the role I am trying to ping/mention.

Answer

yummypasta picture yummypasta · May 30, 2020

The currently accepted answer is incorrect. You ping a user with <@id>, not a role.

As stated in this Github issue, for roles, you have to use <@&id> and the role has to be pingable.

So, the correct code for the question would be something like:

msg.channel.send("<@& " + roleId + "> Found one!! " + msga);

Or, using fancy formatted strings:

msg.channel.send(`<@&${roleId}> Found one!! ${msga}`);