I'm currently working on a system which allows users to create Role Reaction messages. I'm using Enmap (js <=> sqlite database) to store the pairs given by users emojiIdOrName: roleId
.
So, as you can read in the title, I'm having issues with Reactions. When a member reacts with whatever emoji of a message stored in my DB, my code first makes sure that all the emoji-role pairs stored for this message are correct (checks if the stored roles are still available, if all the reactions you see under the message are in the DB and vice versa). If something's wrong, the pair is deleted from the DB and the reaction is deleted from the message. So according to what I said above (if it's clear enough), when you remove an emoji from the message (on discord side, e.g. ), the next time someone reacts should update the database and remove the correspondign entry in the DB before even getting a role. But it actually doesn't.
What I tried
First of all I obviously tried to debug my code by putting some console.logs everywhere. For what I understood, when a reaction was cached once trying to fetch the message again does not update the cache and the reaction still appears to be on the message (when it's not ^^).
So I tried different things I could see around Stackoverflow, like adding the client.on('raw', ....)
bit. It didn't change anything.
Then I tried using partials (I thought it might help smh) for Messages and Reactions. Nothing different.
Even tried iterating other the reactions like so
reaction.message.reactions.cache.forEach(async r => {
await r.fetch();
});
Here is a concrete example of what I said. I just removed a reaction: , only one remaining but here is what I get when logging the reaction emoji: . I'm using the following code
case 'dev':
message.channel.messages.fetch(arguments[1]).then(m => {
console.log(m.reactions.cache.map(r => {r.fetch();return r.emoji.name}))
})
break;
What I did not try (and I don't want to use it)
I don't want to use other events like messageReactionRemove, messageReactionRemoveAll, messageReactionRemoveEmoji etc. as there are too much ways of removing a reaction (it would be a pain to handle all of these).
Making it shorter
To make it shorter, I'd like to be able to fetch a message's real reactions and not get cached ones with the messageReactionAdd
event.
Edit
Ok soo I've been busy trying a few things lately and I found something really interesting. In fact it appears that everything I said above is true but only for reactions added by everyone who isn't the client. I'm now trying to correctly fetch my bot's reactions.