fix(MessageReaction): fetching a removed partial custom emoji #3955
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fixes #3946
After a "partial" MessageReaction (being a custom emoji) was completely removed, the
emoji
getter would return an instance of GuildEmoji which was being passed intoReactionManager#_fetchReaction()
. SinceGuildEmoji#reaction
will always returnundefined
it would end up throwing an error since_patch()
was trying to be called on thatdiscord.js/src/managers/ReactionManager.js
Line 84 in 7994b56
And as for why this doesn't occur within the
messageReactionAdd
event (which was asked on#library-discussion
channel is because that line will only execute when a reaction emoji has been completely removed and/or when all reactions which is checked beforehand.To fix this issue: instead of manually fetching the message and handling the fetched message to update the reactions
Message#fetch()
will be used to indirectly update the reaction, which is much simpler to how it was before so it can be done directly withinMessageReaction#fetch()
to avoid having trouble finding a reference externally to get access to the _patch method. It somewhat does the same by fetching the message and then updatingMessage#reactions
(Message#fetch()
→MessageManager#fetchId()
→MessageManager#add()
→Message#_patch()
→ReactionManager#add()
→ ...MessageReaction#_patch()
). When an emoji / all reactions has been completely removed it wouldn't be present withinMessage#reactions
, soMessageReaction#count
should obviously be set to0
which is handled.
Here's a snippet of how I tested these changes
Status
Semantic versioning classification: