Discord.js: Immediate timeout error on awaitReactions despite options

Created on 29 Feb 2020  ยท  12Comments  ยท  Source: discordjs/discord.js

awaitReactions is timing out immediately when a timeout is set. It's not waiting the designated time. This issue only occurs on Discord.js 11.6.1, downgrading to 11.5.1 resolves the problem (I have been using this code for months).

question.awaitReactions(filter, { max: 1, time: 30000, errors: ['time'] })
    .then(collected => { console.log("Success"); })
    .catch(() => { console.log("Timeout"); })

Further details:

  • discord.js version: 11.6.1
  • Node.js version: 13.9
  • Operating system: Raspbian Buster Lite
  • Priority this issue should have โ€“ please be realistic and elaborate if possible: High, with my understanding of it, it's pretty breaking for anyone wanting to collect emoji this way.

  • [ ] I have also tested the issue on latest master, commit hash:

utility bug

All 12 comments

I cannot reproduce this issue on discord.js version 11.6.1!

I am using () => true for my CollectorFilter to just allow any reaction and I am using the AwaitReactionsOptions you have supplied.

message.awaitReactions(() => true, { max: 1, time: 30000, errors: ["time"] })
  .then(collected => console.log(collected))
  .catch(error => console.log(error));

Perhaps you should consider coming to the Discord server for assistance?

I can only confirm the whole thing. With me he goes through the queries instead of waiting and then of course I get unknown emojis

       const filter = (reaction, user) => {
            return ["gears", "gold", "โŒ"].includes(reaction.emoji.name) && user.id === discordid;
        };

        await FMsg.awaitReactions(filter, { max: 1, time: 30000, errors: ["time"] })
            .then(async collected => {
                const reaction = collected.first();
                if (reaction.emoji.name === "gears") {
                    await FMsg.clearReactions().catch();
                    UnderSetting[FMsg.id] = true;
                    Shop[FMsg.id] = false;
                    reacts(Slots, FMsg, InventoryEmpty);
                }
                if (reaction.emoji.name === "gold") {
                    await FMsg.clearReactions().catch();
                    UnderSetting[FMsg.id] = true;
                    Shop[FMsg.id] = true;
                    reacts(Slots, FMsg, InventoryEmpty);
                }
                if (reaction.emoji.name === "โŒ"){
                    delete Shop[FMsg.id];
                    delete UnderSetting[FMsg.id];
                    FMsg.delete().catch(console.log("T"));
                }
            })
            .catch(errorreaction => {
                delete Shop[FMsg.id];
                delete UnderSetting[FMsg.id];
                console.log(errorreaction);
                FMsg.delete().catch(p => { console.log(errorreaction, p); });
            });

It seems I was mistaken, It's not timing out, it's seeing a reaction that isn't there, or possibly seeing the bots own reaction despite the fact my filter is checking a specific author that invoked the command. But again, it works fine in 11.5.1. I realize I forgot to include the filtering code above, so here is a more complete sample. Specifically in this case it is seeing the 'Answered No' reaction.

```javascript
const filter = (reaction, user) => {
return (user.id === message.author.id && (reaction.emoji.name === '๐Ÿ‡พ' || reaction.emoji.name === '๐Ÿ‡ณ'));
};

const question = await message.reply(User Prompt)
.catch(err => error.fatal(client, message, err));
if (!question) { return; }

await question.react('๐Ÿ‡พ');
await question.react('๐Ÿ‡ณ');
question.awaitReactions(filter, { max: 1, time: 30000, errors: ['time'] })
.then(collected => {
if (collected.get('๐Ÿ‡พ')) {
appendData(authClient, system); // Pass off to google sheets.
} else {
message.react('โŒ');
message.reply('Answered No.');
}
question.delete();
})
.catch(() => {
message.react('โŒ');
message.reply('Timeout.');
question.delete();
});
};```

Seems I'm able to reproduce with the code you've given @Alshain-Aquilae.

However, I can't reproduce on the latest stable version which as of mere moments ago is now 12.0.0. Can you double check?

I'm having the same problem

return message.channel.send("something something").then(res=>{
    res.react('๐Ÿ‘Œ').then(res2=>{
        res.react('โŒ').then(res3=>{
            res.awaitReactions((reaction, user) => (reaction.emoji.name==='๐Ÿ‘Œ' || reaction.emoji.name==='โŒ') && user.id === message.author.id, 
                { max: 1, time: 60000, errors: ['time'] }).then(collected => {
                    console.log("collected",collected.first())
            }).catch(err=>console.log("timeout"))
        })
    })
});

instantly logs out "collected undefined" without clicking anything

"discord.js": "^11.6.1"

11.6.1 is an old version, I recommend retrying on at least the current stable version

yeah seems to work fine on 12.0.1, sadly it required Node v12 which broke other older packages.

I've found the issue, for anyone who still used 11.6.1

https://github.com/discordjs/discord.js/commit/099a1a47e87e00fc770fa3abb1c2c5ea27bf18d0 fixed an issue with MessageCollector and Collector in which max and maxMatches were both being treated as maxMatches. The fix for this included ensuring that the postCheck method of the Collector always runs, even if nothing was collected, to check if it should stop or not.

It looks like this has had the opposite issue with the ReactionCollector, which handles incrementing in the postCheck method but used to only support options for limiting by collected reactions (unintentionally). Now because postCheck will always run, the total on the ReactionCollector is always increasing and a user is always being set, even if the reaction doesn't pass the filter.
https://github.com/discordjs/discord.js/blob/d72172744e832256d1b1eae17cb50b3fa8d5cc20/src/structures/ReactionCollector.js#L69

It should be possible to instead use maxEmojis to address this, since an emoji is only collected if it passes the filter. max and maxUsers will always increment.

I will give that a try when I get home, hopefully it fixes my code and atleast me upgrading haven't caused any other issues. I will also double check my version to see what it is, and then try out your suggestions.

maxEmojis does work to fix 'emoji' is undefined. Thank you sooo much.

I am just having an issue with custom emoji reactions, I have assigned them to a "const" and called them for the reacting which it does. But not the checking. :(

This has been fixed with 11.6.2.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

BrandonCookeDev picture BrandonCookeDev  ยท  3Comments

DatMayo picture DatMayo  ยท  3Comments

Dmitry221060 picture Dmitry221060  ยท  3Comments

ghost picture ghost  ยท  3Comments

Brawaru picture Brawaru  ยท  3Comments