fix(MessageReaction): Prevent event double fire from uncached messages (#6818)

This commit is contained in:
Jiralite
2021-10-16 23:16:05 +01:00
committed by GitHub
parent 38cc89e5ae
commit 267a4b3f68
2 changed files with 14 additions and 11 deletions

View File

@@ -15,7 +15,7 @@ const { PartialTypes } = require('../../util/Constants');
*/
class MessageReactionAdd extends Action {
handle(data) {
handle(data, fromStructure = false) {
if (!data.emoji) return false;
const user = this.getUserFromMember(data);
@@ -30,9 +30,8 @@ class MessageReactionAdd extends Action {
if (!message) return false;
// Verify reaction
if (message.partial && !this.client.options.partials.includes(PartialTypes.REACTION)) return false;
const existing = message.reactions.cache.get(data.emoji.id ?? data.emoji.name);
if (existing?.users.cache.has(user.id)) return { message, reaction: existing, user };
const includePartial = this.client.options.partials.includes(PartialTypes.REACTION);
if (message.partial && !includePartial) return false;
const reaction = message.reactions._add({
emoji: data.emoji,
count: message.partial ? null : 0,
@@ -40,6 +39,7 @@ class MessageReactionAdd extends Action {
});
if (!reaction) return false;
reaction._add(user);
if (fromStructure) return { message, reaction, user };
/**
* Emitted whenever a reaction is added to a cached message.
* @event Client#messageReactionAdd