Discord.js: Users missing when trying to get them from reaction event

Created on 23 May 2020  路  3Comments  路  Source: discordjs/discord.js

Hello I'm working on managment of role by reacting to a message and I don't want the roles to be cumulative. To make it cleaner, I want to remove the reactions of the user to other emojis. But when I want to get users that had reacted with a certain emoji it is empty. It's the same way when I get all reactions of the user on this message.

How to reproduce to bug:

client.on("messageReactionAdd", async (reaction, user) => {
    const userReactions = reaction.message.reactions.cache.filter(reaction => reaction.users.cache.has(user.id));
    console.log(userReactions);
});

Then to react to any message on a server that your bot is in.

For me, it prints : _Collection [Map] {}_

I tried with many other ways (and many time with dirty code 馃槩) but I all the time git the same result...
I think its obviously a bug and I didn't find anyone that talked about it before.

Further details:

  • discord.js version: lastest
  • Node.js version: lastest
  • Operating system: Ubuntu on my computer and NOOB on my Raspberry Pi
  • Priority this issue should have : low
  • [x] I have also tested the issue on latest master, commit hash:
unverified bug

Most helpful comment

I can not exactly reproduce that, @talle117.

If an uncached user adds a reaction, the event will only emit if the USER PartialType is enabled. (Regardless of intents)

See the relevant lines of code here:
https://github.com/discordjs/discord.js/blob/d827544fbd12e827fb4b6ff99d8894ecd79ede02/src/client/actions/MessageReactionAdd.js#L18-L19

Further down the call chain a partial check will be made if the user is not cached:
https://github.com/discordjs/discord.js/blob/d827544fbd12e827fb4b6ff99d8894ecd79ede02/src/client/actions/Action.js#L27-L31

In your cases there is no cached user and no partial type for users enabled, thus the function returns undefined and no event is being emitted.


You probably are not encountering this without intents because you then will have the PRESENCES implicitly enabled and receive initial online members causing the user to be cached.

All 3 comments

Can confirm this.

My code:
client.on("messageReactionAdd", async (reaction, user) => { console.log(reaction); console.log(user); });

Both console logs don't log anything when a user who is not currently cached in the client adds a reaction to a message.
For example, when using the following Discord gateway intents: ['GUILDS', 'GUILD_MESSAGES', 'GUILD_MESSAGE_REACTIONS', 'DIRECT_MESSAGES', 'DIRECT_MESSAGE_REACTIONS'] I get nothing from the messageReactionAdd event if an uncached user reacts to a message that is cached. However, if I remove the gateway intents completely from my client options I get both the user and reaction collection.

Reproduction steps:

  1. Create an event listener for messageReactionAdd and log to console data you get from it.
  2. Set your gateway intents options to the following: ['GUILDS', 'GUILD_MESSAGES', 'GUILD_MESSAGE_REACTIONS', 'DIRECT_MESSAGES', 'DIRECT_MESSAGE_REACTIONS'].
  3. Start the client. Have two Discord accounts ready, one account is to type a message in a channel and the other account is to add a reaction to said message. You will notice that nothing was logged to the console.
  4. Remove your gateway intents options and retry step 3. You will notice now that data was logged in the console.
  • Discord.js - 12.2.0
  • Node - 12.16.1
  • OS - Windows 10, Ubuntu 16.04

I can not exactly reproduce that, @talle117.

If an uncached user adds a reaction, the event will only emit if the USER PartialType is enabled. (Regardless of intents)

See the relevant lines of code here:
https://github.com/discordjs/discord.js/blob/d827544fbd12e827fb4b6ff99d8894ecd79ede02/src/client/actions/MessageReactionAdd.js#L18-L19

Further down the call chain a partial check will be made if the user is not cached:
https://github.com/discordjs/discord.js/blob/d827544fbd12e827fb4b6ff99d8894ecd79ede02/src/client/actions/Action.js#L27-L31

In your cases there is no cached user and no partial type for users enabled, thus the function returns undefined and no event is being emitted.


You probably are not encountering this without intents because you then will have the PRESENCES implicitly enabled and receive initial online members causing the user to be cached.

Please specify actual versions in the template, latest is pretty much useless as it will change over time, @Zargith.
Also if you check I have also tested the issue on latest master, commit hash: actually fill in the commit hash you tested this on.
Again, latest is useless here for the same reason.


To your issue:

If you fetch a message, you will not get any users that added any reactions (read: MessageReaction#users will be empty).
You can manually fetch those in chunks of up to 100 by using MessageReactionUserManager#fetch.

If you have a lot of users using this feature, I'd strongly recommend to do that.

If you however only sparingly have users use this feature, you might be able to get away without caching all of them and simply directly using MessageReactionUserManager#remove on all other reactions. Note that this will likely produce a bunch of 4xx (I assume 404) responses. (Too many of those will get you an automated 1h ban, hence my suggestion above if this is not a sparingly used thing)

Was this page helpful?
0 / 5 - 0 ratings

Related issues

BrandonCookeDev picture BrandonCookeDev  路  3Comments

ghost picture ghost  路  3Comments

xCuzImPro picture xCuzImPro  路  3Comments

tiritto picture tiritto  路  3Comments

LLamaFTL picture LLamaFTL  路  3Comments