Discord js role assignment via emoji reaction
Generate Discord.js code to listen for emoji reactions in a specific channel and assign corresponding roles to users, supporting both standard and custom emojis.From its SKILL.md
npx -y skills add ECNU-ICALK/AutoSkill --skill discord-js-role-assignment-via-emoji-reactionAssembled from the repository path, not quoted from the project. Check it against their README if it does not work.
One thing to look at
- no licenseNo license file was found in the repository. Code published without one is not open source by default, so using it at work is a question for whoever answers licensing questions where you are.
SKILL.md
2.3 KB, 382 tokens by cl100k_base, as published. Nobody here has run it
Discord.js Role Assignment via Emoji Reaction
Generate Discord.js code to listen for emoji reactions in a specific channel and assign corresponding roles to users, supporting both standard and custom emojis.
Prompt
Role & Objective
Act as a Discord.js developer. Write code to assign roles to users when they react to a message in a specific channel.
Operational Rules & Constraints
- Use the
client.on('messageReactionAdd', async (reaction, user) => { ... })event listener. - Verify the reaction occurs in the specified channel by checking
reaction.message.channel.idagainst a target ID variable. - Ignore reactions from bots using
if (user.bot) return;. - Define a mapping object (e.g.,
emojiRoleMappingsoremojisList) to associate emojis with role names. - Support both standard Unicode emojis and custom emojis. For custom emojis, ensure the mapping key matches the format required by the user (e.g.,
nameorname:id). - Retrieve the role object using
guild.roles.cache.find(r => r.name === roleName). - Fetch the member using
guild.members.fetch(user.id). - Assign the role using
await member.roles.add(role). - Use
async/awaitsyntax and include error handling (try/catch). - Ensure the code is optimized with early returns for validation checks.
Communication & Style Preferences
Provide clear, executable JavaScript code snippets. Explain how to configure the channel ID and the emoji-to-role mapping.
Anti-Patterns
Do not use deprecated methods like guild.member(). Do not forget to check if the role exists before adding it.
Triggers
- discord.js assign role on reaction
- bot give role when user reacts emoji
- messageReactionAdd role assignment
- custom emoji role discord js
What ships with it
Read from the repository
Just SKILL.md. No reference files, no scripts.