discordjs / discord.js

A powerful JavaScript library for interacting with the Discord API
https://discord.js.org
Apache License 2.0
25.35k stars 3.97k forks source link

Reaction doesn't collect at second collector #4894

Closed Gorott closed 4 years ago

Gorott commented 4 years ago

Please describe the problem you are having in as much detail as possible: So i am currently working on a settings menu with reactions the problem is that the only the first collector works which is '1️⃣'

Include a reproducible code sample here, if possible:

const no = client.emojis.cache.get('761994824957165569');
const yes = client.emojis.cache.get('761994859858755615');
const settingsEmbed = new Discord.MessageEmbed()
    .setTitle('Settings:')
    .setDescription(
        `**Role Settings: \n if role settings is turned on roles will be created when someone finished the setup.`
    );
msg.channel.send(settingsEmbed).then(m => {
    const filter_one = (reaction, user) => {
        return reaction.emoji.name === '1️⃣' && user.id === msg.author.id;
    };
    const collector_one = m.createReactionCollector(filter_one);

    const filter_two = (reaction, user) => {
        return reaction.emoji.name === '2️⃣' && user.id === msg.author.id;
    };
    const collector_two = m.createReactionCollector(filter_two);

    m.react('1️⃣').then(messageReaction => {
        messageReaction.message.react('2️⃣');
    });

    collector_one.on('collect', () => {
        collector_one.stop();
        collector_two.stop();

        const roleEmbed = new Discord.MessageEmbed()
            .setTitle(`Role Settings: `)
            .setDescription(
                `This will create a role and give it to the person that finished the setup.`
            );

        m.edit(roleEmbed);

        const filter_yes = (reaction, user) => {
            return reaction.emoji.name === yes && user.id === msg.author.id
        };
        const collector_yes = m.createReactionCollector(filter_yes);

        const filter_no = (reaction, user) => {
            return reaction.emoji.name === no && user.id === msg.author.id;
        };
        const collector_no = m.createReactionCollector(filter_no);

        m.react(yes).then(messageReaction => {
            messageReaction.message.react(no);
        });
        collector_yes.on('collect', () => {
            console.log('reacted yes');
        });
    });
});
}

utils.editEmbed and utils.sendEmbed just work the same as a normal embed creation

Further details:

Relevant client options:

almostSouji commented 4 years ago

Please provide a minimal reproducible code sample so we can attempt to reproduce and verify your issue. This means isolating the erroneous behavior to a fresh bot, or stripping away functionality until you can be sure the code is minimal. Also include a manual with the steps you take interacting with the code in question which results in the behavior you outlined.

Please try to reproduce the issue yourself on a fresh bot. If you can't reproduce it, it's very likely that we can't either and the code sample in question is not enough.

Boilerplate: https://discord.js.org/#/docs/main/stable/examples/ping Minimal Reproducible sample: https://stackoverflow.com/help/minimal-reproducible-example

Gorott commented 4 years ago

done

almostSouji commented 4 years ago

I can not find a reproducible bug here, if you still find an issue in it please detail the exact operation of actions you take, what you expect to happen and what happens instead.

So this is a diagram of the logical flow in the provided code:

- start collector for emoji (1)
- start collector for emoji (2)
- react with both emojis (1), (2)
- - reacting with (1):
- - - stop collector for emoji (1)
- - - stop collector for emoji (2)
- - - start collector for (tick)
- - - start collector for (X)
- - - react with both emojis (tick), (x)
- - - - reacting with (tick)
- - - - - console log
- - - - reacting with (x)
- - - - - <no operation>
- - reacting with (2):
- - - <no operation>

Accordingly the only branches that results in an actions are:

  1. react with (1)
  2. react with (tick)

  1. react with (2) or anything else, really - as it does nothing
  2. react with (1)
  3. react with (tick)

Which works as intended:

demo


You maybe want to consider consolidating this into a single (or maybe two) collectors. You do not need to create a separate collector for each of the emojis, you can just as well check for both emojis in a single collector and filter ["unicode_1", "unicode_2"].includes(reaction.emoji.name) and handle the further path (which emoji was collected) in the "collect" event callback.

collector.on("collect", collected => {
    if (collected.first().emoji.name === "unicode_1") {
        // ...
    } else {
        // ...
    }
})

Resources: discordjs.guide Invite to the support server if you have more questions on collectors (as this repository is only for bug reports and feature requests): https://discord.gg/bRCvFy9

Gorott commented 4 years ago

ezgif com-gif-maker (2)

it's strange that it works perfectly fine for you since it really doesn't work for me. what could be the cause for it to not work?

almostSouji commented 4 years ago

From how this behaves you are not running the exact code you provided as minimal sample above (which is what this report should be centered around), which makes this demonstration rather irrelevant.

The exact code above will behave the exact same on the tested version of the library 12.3.1. There is no reason why it might behave differently for you, should you use this version and the provided code.

As for your original code (which you seem to be running in your demo): Log around, try and find out where execution stops/filters are passed/collectors end/input arrives - possibly by attaching more listeners (for end) and monitoring the behavior.

If you can actually still reproduce after running the minimal code sample feel free to re-open.

Gorott commented 4 years ago

@almostSouji seems like i found out what the problem is (don't know how to fix it) updated the example hope u can do something with it

almostSouji commented 4 years ago

you compare names with ids in your second set of filters.

If you need help with discord.js installation or usage, please go to the discord.js Discord server instead: https://discord.gg/bRCvFy9 This issue tracker is only for bug reports and enhancement suggestions. You won't receive any basic help here.