Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Fetch old reactions to an old message

Tags:

discord.js

I've written a discord.js bot with version 12.0.2 and some features have been running for a while but are now disfunctionning and it seems to be related to empty cache, but I can't manage to figure out how to solve it.

Here is the scenario :

I have my bot weekly posting a message on a server and guild members have a week to react to this message. At the end of the week, I want to analyze the reactions to the bot to decide what to do (I can't have the bot running 24/7 to await for reactions).

Here is my problem :

Once I've fetched this specific message, what I did until now was msg.reactions.resolve('✅').users.fetch().then(somestuff), but since a few weeks it stopped functionning and now throws (node:2336) UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'users' of null.

I've been through some debugging steps and found out that msg.reactions.cache is empty, hence here I think the problem is, but I cannot find how to fill it. Here is what msg.reactions contains:

ReactionManager {
  cacheType: [Function: Collection],
  cache: Collection [Map] {},
  message: Message {
    details_about_the_message_that_confirm_it_is_the_desired_one_that_have_been_reacted_to
  }
}

Would anybody have ideas about how to solve this please ? Any help would be much appreciated, thank you !

like image 773
Jueverhard Avatar asked Nov 20 '25 10:11

Jueverhard


1 Answers

I've finally found a solution, or maybe I'd better call it a workaround, hence I'm sharing it here to close this post.

First of all, I have to say that msg.reactions.resolve('✅').users.fetch().then(somestuff) does its work and is not part of the problem, as the problem was lying in the message fetching process. Fetching a bunch of messages or fetching a specific one (i.e. by ID) leads to different results.

Fetching a specific message by ID let you access the ReactionManager's cache, while fetching several messages seems not to populate the cache.

like image 59
Jueverhard Avatar answered Nov 22 '25 04:11

Jueverhard



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!