How to create role-specific emojis

I’d like to create a command that will restrict an existing GuildEmoji to the role(s) that I specify. For example: !restrictemote <Emote ID> <Role ID(s)>. Then, only members with those roles will be able to use the emote. How go I come about doing this?

I checked the Discord role settings, there doesn’t seem to be any editable emote options besides being able to react to messages and being able to use emotes from other servers.

Add Comment
1 Answer(s)

discord.js actually has that functionality built-in with the GuildEmojiRoleManager class. The default collection is empty, making every emote accessible to every role. However, you can change that using the .add(), .remove(), and .set() methods.

Here’s how you can use it for your command:

message.guild.emojis.cache.get('<Emote ID>') // first, get the emoji    .roles // then the current role restrictions (default: none)    .add(['<Role ID>', '<Role ID>'); // then add, set, or remove the specified roles 

Here’s a demonstration from my Discord server:


I started being able to use the emote just fine, but after a role was added to the GuildEmojiRoleManager cache that I did not have, I was not able to use it anymore. It didn’t even show up in my emoji dashboard/picker, so I had to manually write <a:coin:733804322214903848>, and even that didn’t work.

Answered on August 31, 2020.
Add Comment

Your Answer

By posting your answer, you agree to the privacy policy and terms of service.