mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-17 20:13:30 +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 {
|
class MessageReactionAdd extends Action {
|
||||||
handle(data) {
|
handle(data, fromStructure = false) {
|
||||||
if (!data.emoji) return false;
|
if (!data.emoji) return false;
|
||||||
|
|
||||||
const user = this.getUserFromMember(data);
|
const user = this.getUserFromMember(data);
|
||||||
@@ -30,9 +30,8 @@ class MessageReactionAdd extends Action {
|
|||||||
if (!message) return false;
|
if (!message) return false;
|
||||||
|
|
||||||
// Verify reaction
|
// Verify reaction
|
||||||
if (message.partial && !this.client.options.partials.includes(PartialTypes.REACTION)) return false;
|
const includePartial = this.client.options.partials.includes(PartialTypes.REACTION);
|
||||||
const existing = message.reactions.cache.get(data.emoji.id ?? data.emoji.name);
|
if (message.partial && !includePartial) return false;
|
||||||
if (existing?.users.cache.has(user.id)) return { message, reaction: existing, user };
|
|
||||||
const reaction = message.reactions._add({
|
const reaction = message.reactions._add({
|
||||||
emoji: data.emoji,
|
emoji: data.emoji,
|
||||||
count: message.partial ? null : 0,
|
count: message.partial ? null : 0,
|
||||||
@@ -40,6 +39,7 @@ class MessageReactionAdd extends Action {
|
|||||||
});
|
});
|
||||||
if (!reaction) return false;
|
if (!reaction) return false;
|
||||||
reaction._add(user);
|
reaction._add(user);
|
||||||
|
if (fromStructure) return { message, reaction, user };
|
||||||
/**
|
/**
|
||||||
* Emitted whenever a reaction is added to a cached message.
|
* Emitted whenever a reaction is added to a cached message.
|
||||||
* @event Client#messageReactionAdd
|
* @event Client#messageReactionAdd
|
||||||
|
|||||||
@@ -717,14 +717,17 @@ class Message extends Base {
|
|||||||
*/
|
*/
|
||||||
async react(emoji) {
|
async react(emoji) {
|
||||||
if (!this.channel) throw new Error('CHANNEL_NOT_CACHED');
|
if (!this.channel) throw new Error('CHANNEL_NOT_CACHED');
|
||||||
emoji = this.client.emojis.resolveIdentifier(emoji);
|
|
||||||
await this.channel.messages.react(this.id, emoji);
|
await this.channel.messages.react(this.id, emoji);
|
||||||
return this.client.actions.MessageReactionAdd.handle({
|
|
||||||
user: this.client.user,
|
return this.client.actions.MessageReactionAdd.handle(
|
||||||
channel: this.channel,
|
{
|
||||||
message: this,
|
user: this.client.user,
|
||||||
emoji: Util.parseEmoji(emoji),
|
channel: this.channel,
|
||||||
}).reaction;
|
message: this,
|
||||||
|
emoji: Util.resolvePartialEmoji(emoji),
|
||||||
|
},
|
||||||
|
true,
|
||||||
|
).reaction;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user