Search code examples
javascriptdiscorddiscord.jsroles

Discord.js Assign a role based off a certain message reaction


I Want it so if a member does a certain reaction to a certain message. it will give them a role. i know how to add a role

let role6 = member.guild.roles.cache.find(role => role.name == "Member");
if(!role6) return;
user.roles.add(role6);

but I'm not sure who to get it to be triggered by a :white_check_mark: reaction to a certain message in a channel. any ideas?


Solution

  • You can use the messageReactionAdd event, which will emit when someone reacts to a message.

    client.on('messageReactionAdd', (reaction, user) => {
     if (reaction.message.id !== 'Message ID') return;
     const role6 = member.guild.roles.cache.find((role) => role.name == 'Member');
     if (!role6) return;
     reaction.guild.member(user).roles.add(role6);
    });