From 267a4b3f68fa81629a083ebf04f7e49b5579ae86 Mon Sep 17 00:00:00 2001 From: Jiralite <33201955+Jiralite@users.noreply.github.com> Date: Sat, 16 Oct 2021 23:16:05 +0100 Subject: [PATCH] fix(MessageReaction): Prevent event double fire from uncached messages (#6818) --- src/client/actions/MessageReactionAdd.js | 8 ++++---- src/structures/Message.js | 17 ++++++++++------- 2 files changed, 14 insertions(+), 11 deletions(-) diff --git a/src/client/actions/MessageReactionAdd.js b/src/client/actions/MessageReactionAdd.js index 452ed6b12f05..e5f5d1deb4c4 100644 --- a/src/client/actions/MessageReactionAdd.js +++ b/src/client/actions/MessageReactionAdd.js @@ -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 diff --git a/src/structures/Message.js b/src/structures/Message.js index e3a6ee464dee..31727407ee08 100644 --- a/src/structures/Message.js +++ b/src/structures/Message.js @@ -717,14 +717,17 @@ class Message extends Base { */ async react(emoji) { if (!this.channel) throw new Error('CHANNEL_NOT_CACHED'); - emoji = this.client.emojis.resolveIdentifier(emoji); await this.channel.messages.react(this.id, emoji); - return this.client.actions.MessageReactionAdd.handle({ - user: this.client.user, - channel: this.channel, - message: this, - emoji: Util.parseEmoji(emoji), - }).reaction; + + return this.client.actions.MessageReactionAdd.handle( + { + user: this.client.user, + channel: this.channel, + message: this, + emoji: Util.resolvePartialEmoji(emoji), + }, + true, + ).reaction; } /**