mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-09 16:13:31 +01:00
fix(MessageReaction): Prevent event double fire from uncached messages (#6818)
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user