'discord.js Problem with reaction roles. Bot didn't give the role

I'm trying to code bot that has reaction role function. My bot adds reactions to the message, but when I'll react to the message nothing happens. Bot should give me a "user" role. All permissions are set up in my discord server.

I'm using 13.6.0 discord.js like my package.json file said. I'm still beginner in this stuff so please be understanding.

Here's my main.js code:


const client = new Discord.Client({ intents: ["GUILDS", "GUILD_MESSAGES"] , partials: ["MESSAGE" , "CHANNEL" , "REACTION"]  });



const prefix = '-';

const fs = require('fs');

client.commands = new Discord.Collection();

const commandFiles = fs.readdirSync('./commands/').filter(file => file.endsWith('.js'));
for(const file of  commandFiles){
    const command = require(`./commands/${file}`);
    
    client.commands.set(command.name, command);  
}


client.once('ready', () => {
    console.log('BOT is online!');
});

client.on('messageCreate' , message => {


    if(!message.content.startsWith(prefix) || message.author.bot) return;

    const args = message.content.slice(prefix.length).split(/ +/);
    const command = args.shift().toLowerCase();

    if(command === 'command') {
        client.commands.get('command').execute(message, args, Discord);
    }
    else if (command === "rr") {
        client.commands.get('rr').execute(message, args, Discord, client);
    }
    else if (command === 'weryfikacja') {
        client.commands.get('weryfikacja').execute(message, args, Discord);
    }
});

client.login('EMPTY')

Here's my rr.js code:

module.exports = {
    name: "rr",
    description: "Create reaction roles!",
    execute(message, args, Discord, client) {

if(!args[0] || !args[1] || !args[2] === null) {
    message.channel.send("You did not provide all the arguments!");
    return;
}

message.delete();

let reactionroleserver = message.guild.roles.cache.get(args[2]);

message.channel.messages.fetch(args[0]).then(message => message.react(args[1]));

let emojiToReact = args[1];

client.on('messageReactionAdd', async (reaction, user) =>{
    if (reaction.message.partial) await reaction.message.fetch();
    if (reaction.partial) await reaction.fetch();
    if (user.bot) return;
    if (!reaction.message.guild) return;

    if(reaction.emoji.name === emojiToReact) {
        await reaction.message.guild.members.cache.get(user.id).roles.add(reactionroleserver);
    } else {
        return;
    }
})

client.on('messageReactionRemove', async (reaction, user) =>{
    if (reaction.message.partial) await reaction.message.fetch();
    if (reaction.partial) await reaction.fetch();
    if (user.bot) return;
    if (!reaction.message.guild) return;

    if(reaction.emoji.name === emojiToReact) {
        await reaction.message.guild.members.cache.get(user.id).roles.remove(reactionroleserver);
    } else{
        return;
    }
})
    }
}



Solution 1:[1]

Enable GUILD_MESSAGE_REACTIONS intent

const client = new Discord.Client({ 
  intents: [
    "GUILDS", 
    "GUILD_MESSAGES",
    "GUILD_MESSAGE_REACTIONS"
  ], 
  partials: [
    "MESSAGE", 
    "CHANNEL", 
    "REACTION"
  ]  
})

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 MrMythical