Discord.js: How to mention people in a role?

Created on 6 Jun 2016  路  7Comments  路  Source: discordjs/discord.js

I would like my bot to be able to mention and notify anyone in a role when called... For example if someone calls the role "@role" i would like everyone in that role to be mentioned...

Thanks in advance!

question (please use Discord instead)

All 7 comments

<@&roleID>, but this should probably be added to Role itself

Well then RoleObject.mention() would also work

Hey @abalabahaha

How can you use roles in your code? For example if there is a role called @here how would you notify anyone inside that role?

The actual @here (Discord's implementation of it) would simply be "@here". If you had a role called here you could use its object and call its mention() function. Ex.:

bot.on("message", msg => {
    if(msg.content == "mention") {
        var hereRole = msg.channel.server.roles.get('name', 'here');

        // All of these three produce the same output
        // 1
        bot.sendMessage(msg, hereRole.mention() + " is anyone here?");
        // 2
        bot.sendMessage(msg, hereRole.toString() + " is anyone here?");
        // 3
        bot.sendMessage(msg, hereRole + " is anyone here?");
    }
});

Thanks a lot @GexoXYZ, i will now try if it works, thanks again for your time helping me!

Can I add this in to my bot using a const?

Was this page helpful?
3 / 5 - 2 ratings

Related issues

LLamaFTL picture LLamaFTL  路  3Comments

xCuzImPro picture xCuzImPro  路  3Comments

ghost picture ghost  路  3Comments

shukriadams picture shukriadams  路  3Comments

Brawaru picture Brawaru  路  3Comments