AutoSkill 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.
install
source · Clone the upstream repo
git clone https://github.com/ECNU-ICALK/AutoSkill
Claude Code · Install into ~/.claude/skills/
T=$(mktemp -d) && git clone --depth=1 https://github.com/ECNU-ICALK/AutoSkill "$T" && mkdir -p ~/.claude/skills && cp -r "$T/SkillBank/ConvSkill/english_gpt3.5_8_GLM4.7/discord-js-role-assignment-via-emoji-reaction" ~/.claude/skills/ecnu-icalk-autoskill-discord-js-role-assignment-via-emoji-reaction && rm -rf "$T"
manifest:
SkillBank/ConvSkill/english_gpt3.5_8_GLM4.7/discord-js-role-assignment-via-emoji-reaction/SKILL.mdsource content
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
event listener.client.on('messageReactionAdd', async (reaction, user) => { ... }) - Verify the reaction occurs in the specified channel by checking
against a target ID variable.reaction.message.channel.id - Ignore reactions from bots using
.if (user.bot) return; - Define a mapping object (e.g.,
oremojiRoleMappings
) to associate emojis with role names.emojisList - Support both standard Unicode emojis and custom emojis. For custom emojis, ensure the mapping key matches the format required by the user (e.g.,
orname
).name: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
syntax and include error handling (try/catch).async/await - 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