0
votes

I'm working on a discord bot which adds the role "Voteur" when a user reacts on a embed message created by the bot. Until today it has worked great, but I don't know why doesn't word anymore.

The bot creates the embed message and add the reactions but nothing happens when a user reacts!

Are there any changes that I don't know about in the discord.js v12 API?

Here is my code (it's the file of the !vote command which triggers the embed message):

const Discord = require('../node_modules/discord.js');
const bot = new Discord.Client();
const rappelVote = require('./rappelVote');
const { roleVoteur, image, thumbnail  } = require('..//config.js');

module.exports = function embedVote (channel) {         //Affichage pour les votes
    const voteEmbed = new Discord.MessageEmbed()    //Construction du Embed
        .setColor("13ff00")
        .setTitle("Votez pour Fever sur TopServeur !")
        .setURL("https://top-serveurs.net/gta/feverrp")
        .setDescription("Pour recevoir des rappels de vote et soutenir le serveur, réagissez avec ????")
        .setImage(image)
        .setThumbnail(thumbnail)
        .setFooter("Pour ne plus recevoir les rappels : ????")
     channel.send("@everyone")
     channel.send(voteEmbed)
     
    .then(message => { // envoi une réaction grâce a la promise
        message.react('????')
        message.react('????')

        bot.on('messageReactionAdd', (reaction, user) => { // on vérifie que ce soit bien la bonne réaction et on ne compte pas celui du bot
            const member = message.guild.members.cache.get(user.id);
            const voteur = message.guild.roles.cache.get(roleVoteur);
            if (reaction.emoji.name === '????' && user.id !== bot.user.id) {  
                member.roles.add(voteur);
            }
            if (reaction.emoji.name === '????' && user.id !== bot.user.id) {  
                member.roles.remove(voteur);
            }
        });
    });
    channel.send("<@&" + roleVoteur + ">");
    channel.send(rappelVote());
}

How can I make this work again?

1

1 Answers

0
votes

The problem is probably that you are creating a new Discord.Client() instead of requiring the current one. You should edit your function parameters to include a bot object:

function embedVote (channel, bot) {}

This way you'll be using the correct instance of your client. Example of calling this function correctly:

// if function is being triggered via command

embedVote(message.channel, message.client);

// or something like:

embedVote(bot.channels.cache.get('Channel ID'), bot);