Skip to content

message reaction could not get user's selected reaction from cache after rebooting bot #8843

@lokyse

Description

@lokyse

Which package is this bug report for?

discord.js

Issue description

User choose some reaction in the message, so the reaction records the user's info, and we could use messageReaction.users.remove(user.id) method to remove this user(who has selected the reaction) by id in the reaction that mean user unselect the reaction.

The issue it that if I reboot bot program , The program could fetch message and reactions belong to message at 'messageReactionAdd' event handler. But the reaction don't have those user who has selected it before reboot bot program.
I see MessageReaction.users.cache.get(user.id) method don't give me the user as expected instead of 'undefine' value.

Code sample

client.on("messageReactionAdd", async (reaction, user) => {
            if (user.id === client.user.id) return;

            if (reaction.partial) {
                  // If the message this reaction belongs to was removed, the fetching might result in an API error which should be handled
                  try {
                        await reaction.fetch();
                  } catch (error) {
                        console.error(
                              "Something went wrong when fetching the message:",
                              error
                        );
                        return;
                  }
            }

//   omit  code ....
// ....



  const userReactions =
                                          reaction.message.reactions.cache.filter(
                                                (reaction) =>
                                                      reaction.emoji.name ==
                                                            selected.choiceEmoji &&
                                                      reaction.message.id ==
                                                            selected.pollId
                                          );


                                    userReactions.forEach((e) => {
                                          // has value
                                          console.log(e.emoji.name, e.count);
        
                                          // not work here!  got 'undefine' 
                                          e.users.cache.get(user.id)
 
                                         // e.users.remove(user.id);
                                    });

Package version

^14.6.0"

Node.js version

v18.12.0

Operating system

macos catalina 10.15.7

Priority this issue should have

High (immediate attention needed)

Which partials do you have configured?

User, Channel, Message, Reaction

Which gateway intents are you subscribing to?

Guilds, GuildEmojisAndStickers, GuildMessages, GuildMessageReactions, DirectMessages, DirectMessageReactions, MessageContent

I have tested this issue on a development release

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions