0
votes

I'm building a bot sending an embed and collecting reaction from it. Upon reaction, the bot edit its embed to show all the users who reacted.

Sometimes, it works for 2 or 3 users reaction quickly, especially when the bot starts. But, afterward, it doesn't collect anymore reactions.

The bot is hosted on Heroku, using worker in procfile.

I tried on local, but, sometimes, it blocks after 1 user reaction.

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

function sendEmbed(message) {

    var users = [];

    message.channel.send(startingEmbed).then(async function(message){
    
    const filter = (reaction, user) => reaction.emoji.name === '????';
    const collector = message.createReactionCollector(filter, { max: 50, time: 3 * 24 * 60 * 60 * 1000 });

    collector.on('collect', async (reaction, user) => {
        
        var users = [];
        
        console.log(`Collected ${reaction.emoji.name} from ${user.tag}`);
        if (reaction.message.partial) await reaction.message.fetch();
        if (reaction.partial) await reaction.fetch();
        
        var result = false;
        for (var u in users) {
            if (users[u].name === user.username) {
                result = true;
                break;
            }
        }

        if(result == false) {
           
          var roll = {};
          roll.name = user.username;
          roll.value = random(); //Math.random() method
          users.push(roll);
          
          var description = '';
          users.forEach(element => {
              description += '???? ' + element.value + ' for ' + element.name + '\n';
          });
          
          var edittedEmbed = new Discord.MessageEmbed()
            .setColor('#0099ff')
            .addFields(
                { name: 'rolls', value: `${description}`, inline: true },
            );
        
          message.edit(edittedEmbed);
          
          console.log('newest user ' + roll.name + ' ' + roll.value);
          
          users.forEach(element => console.log('user table' + element.name + ' ' + element.value));
       }
    });
1

1 Answers

0
votes

nevermind, This issue is caused by discord api. It was fixed by adding GUILD_MEMBER to the partials.

As documented : https://github.com/discordjs/discord.js/issues/4980#issuecomment-723519865