Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 9 commits into from Oct 16, 2021
8 changes: 4 additions & 4 deletions src/client/actions/MessageReactionAdd.js
Expand Up @@ -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);
Expand All @@ -30,16 +30,16 @@ 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,
me: user.id === this.client.user.id,
});
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
Expand Down
17 changes: 10 additions & 7 deletions src/structures/Message.js
Expand Up @@ -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);
Jiralite marked this conversation as resolved.
Show resolved Hide resolved
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;
Jiralite marked this conversation as resolved.
Show resolved Hide resolved
}

/**
Expand Down