reaction role by id discord.js

const Discord = require('discord.js');
const client = new Discord.Client({ partials: ['MESSAGE', 'CHANNEL', 'REACTION'] }); //partials arent really needed but I woudld reccomend using them because not every reaction is stored in the cache (it's new in v12)
const prefix = "-";

client.on('messageReactionAdd', async (reaction, user) => {
    if (reaction.partial) { //this whole section just checks if the reaction is partial
        try {
            await reaction.fetch(); //fetches reaction because not every reaction is stored in the cache
        } catch (error) {
            console.error('Fetching message failed: ', error);
            return;
        }
    }
    if (!user.bot) {
        if (reaction.emoji.id == yourEmojID) { //if the user reacted with the right emoji

            const role = reaction.message.guild.roles.cache.find(r => r.id === yourRoleID); //finds role you want to assign (you could also user .name instead of .id)

            const { guild } = reaction.message //store the guild of the reaction in variable

            const member = guild.members.cache.find(member => member.id === user.id); //find the member who reacted (because user and member are seperate things)

            member.roles.add(role); //assign selected role to member

        }
    }
})

Are there any code examples left?
Create a Free Account
Unlock the power of data and AI by diving into Python, ChatGPT, SQL, Power BI, and beyond.
Sign up
Develop soft skills on BrainApps
Complete the IQ Test
Relative searches
add role with reaction discord js how to give a role with reactions discord js reaction roles source code discord.js reaction roles add command discord.js reaction role in discord.js discord.js give roles depending on reaction discordjs reaction role discord.js react role discord.js simple reaction roles reaction role discord.js code discord.js add role on message reaction discord js reaction role bot discord.js on reaction add role discord js get role on reaction role reaction in discord.js reaction roles per guild discord.js discord js message reaction give role give role react message discord.js reaction roles discords.js how to make reaction roles with discord.js discord.js reaction role command discord.js get roles of reaction reaction roles discord.js source code discord.js on reaction role react to get role discord.js find role by reaction discord.js how to make reaction roles discord.js DISCORDJS new reaction role discord.js v12 reaction role working reaction role discord.js code discord.js add reaction role discord.js how to make a reaction roles command how to make a reaction role command discord.js how to make reaction role commands on discord.js how to make a reaction role discord.js discord js give role to reaction discord.js reaction role bot Reaction role Discord js v12 reaction role bot discord.js how to do reaction roles in discord.js discord js react role discord.js react to role give role when reaction discord js discord.js how to make reaction roles discord js reaction roles reaction role discord js give role with reaction discord.js reaction roles discord js give a role based of of reactions discord.js reaction roles, discord.js discord js reaction role get a role with a reaction in discord.js how to get a role with a reaction in discord.js discord js add role on reaction discord js role reaction role reaction discord js How to make reaction roles discord js discord.js reaction roles reaction roles discordd.js discord.js reaction role role reaction discord.js how to make reaction roles on discord.js reaction role discord.js role reactions discord.js reaction role message discord js reaction roles discord.js discord.js role reaction reaction role discordjs reaction role command discord.js give role by id discord.js reactions role discord.js how to get role id discord discord.edit.role get a role with specific id discord get role with react discord.js discord js v12 role reaction reaction role by id discord.js
Made with love
This website uses cookies to make IQCode work for you. By using this site, you agree to our cookie policy

Welcome Back!

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign in
Recover lost password
Or log in with

Create a Free Account

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign up
Or sign up with
By signing up, you agree to the Terms and Conditions and Privacy Policy. You also agree to receive product-related marketing emails from IQCode, which you can unsubscribe from at any time.
Creating a new code example
Code snippet title
Source