0
votes

This is my discord bot im working on recently, after i moved all the code to my VPS the reactionroles don't work anymore.

So for some reason every time you click the emoij it doesn't add the role to the user, i've tried a lot but nothing worked. It seems like it should work, am i missing something? When i start the bot everything seems alright, even the command works. I havn't made any mistakes in the role.id because i tried role.name aswell and entered the name in there. This didn't work either, i hope you have enough info.

The first part is the index.js and the second part is the module i used.

//This is the index.js
const Discord = require('discord.js');
const bot = new Discord.Client({partials: ["MESSAGE", "CHANNEL", "REACTION"]});
const fs = require('fs');

const prefix = '!';

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

bot.commands = new Discord.Collection();

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

    bot.commands.set(command.name, command)
}

bot.on('message', 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 === 'reactionrole') {
        bot.commands.get('reactionrole').execute(message, args, Discord, bot);
    } else if (command === 'twitchandyoutube') {
        bot.commands.get('twitchandyoutube').execute(message, args, Discord, bot);
    } else if (command === 'games') {
        bot.commands.get('games').execute(message, args, Discord, bot);
    } else if (command === 'clear') {
        bot.commands.get('clear').execute(message, args);
    }
});

bot.login(This is my very secret token :) );



//this is the module i made.
module.exports = {
    name: 'games',
    description: "Select the games",
    async execute(message, args, Discord, bot) {
        if(message.member.roles.cache.has('794900472632836116')) {
        const channel = '795030215361429565';
        const rlRole = message.guild.roles.cache.find(role => role.name === "Rocket League");
        const csgoRole = message.guild.roles.cache.find(role => role.name === "Counter-Strike Global Offensive");

        const rl = ('<:RocketLeague:796401366804856842>');
        const csgo = ('<:CSGO:796402447739912202>');
        const rlEmoij = ('796401366804856842');
        const csgoEmoij = ('796402447739912202');

        let embed = new Discord.MessageEmbed()
            .setColor('#e42643')
            .setTitle('Game selection')
            .setDescription(`What games do you play?
                            Select here which games you like to play and see the text/voice channels from.\n\n`
                + `${rl}   **(**    Rocket League                       **)**\n`
                + `${csgo}   **(**    Counter-Strike Global Offensive     **)**`);
        
        let messageEmbed = await message.channel.send(embed);
        messageEmbed.react(rlEmoij);
        messageEmbed.react(csgoEmoij);

        bot.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.message.channel.id == channel) {
                if (reaction.emoji.name === rlEmoij) {
                    await reaction.message.guild.members.cache.get(user.id).roles.add(rlRole);
                }
                if (reaction.emoji.name === csgoEmoij) {
                    await reaction.message.guild.members.cache.get(user.id).roles.add(csgoRole);
                }
            } else {
                return;
            }
 
        });

        bot.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.message.channel.id == channel) {
                if (reaction.emoji.name === rlRole) {
                    await reaction.message.guild.members.cache.get(user.id).roles.remove(rlRole);
                }
                if (reaction.emoji.name === csgoEmoij) {
                    await reaction.message.guild.members.cache.get(user.id).roles.remove(csgoRole);
                }
            } else {
                return;
            }
        });
       } else {
        message.channel.send("You don't have the right permissions to do this.");
 
}
}
} 
1

1 Answers

0
votes

In both events (messageReactionAdd, messageReactionRemove) you're checking if the reaction.emoji.name is rlEmoij / csgoEmoij.

But the property reaction.emoji.name is only the name of the emoji. So in your case it would be RocketLeague or CSGO. You need to get the ID: reaction.emoji.id.

Do something like this:

if (reaction.emoji.id === rlEmoij) {
    await reaction.message.guild.members.cache.get(user.id).roles.add(rlRole);
}
if (reaction.emoji.id === csgoEmoij) {
    await reaction.message.guild.members.cache.get(user.id).roles.add(csgoRole);
}