Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I mention a role with Discord.js?

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.

like image 361
RtHAitP30D Avatar asked Nov 07 '19 13:11

RtHAitP30D


4 Answers

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}`);
like image 74
yummypasta Avatar answered Sep 22 '22 00:09

yummypasta


Just add an opening and closing angle bracket and use the role id to make the mention.

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

This answer was valid for older versions of discord.js (I believe v11 and under) but is now invalid for v12+ use yummypasta's solution for the newer versions.

like image 25
Thomas Reichmann Avatar answered Sep 22 '22 00:09

Thomas Reichmann


It is:

 message.channel.send(`<@& id >`); 
like image 41
soey_sause Avatar answered Sep 22 '22 00:09

soey_sause


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

like image 31
Yusa Avatar answered Sep 22 '22 00:09

Yusa