From d15dd5f07dab00e8a31f0a37b1e60ea4017871d0 Mon Sep 17 00:00:00 2001 From: SpaceEEC Date: Sun, 3 Oct 2021 15:04:37 +0200 Subject: [PATCH] fix(ReactionCollector): only call the filter function once (#6734) --- src/structures/ReactionCollector.js | 27 +++++++++++++-------------- typings/index.d.ts | 2 +- 2 files changed, 14 insertions(+), 15 deletions(-) diff --git a/src/structures/ReactionCollector.js b/src/structures/ReactionCollector.js index 246c3fb3bed4..f524105249f9 100644 --- a/src/structures/ReactionCollector.js +++ b/src/structures/ReactionCollector.js @@ -67,6 +67,17 @@ class ReactionCollector extends Collector { }); this.on('collect', (reaction, user) => { + /** + * Emitted whenever a reaction is newly created on a message. Will emit only when a new reaction is + * added to the message, as opposed to {@link Collector#collect} which which will + * be emitted even when a reaction has already been added to the message. + * @event ReactionCollector#create + * @param {MessageReaction} reaction The reaction that was added + * @param {User} user The user that added the reaction + */ + if (reaction.count === 1) { + this.emit('create', reaction, user); + } this.total++; this.users.set(user.id, user); }); @@ -81,10 +92,10 @@ class ReactionCollector extends Collector { * Handles an incoming reaction for possible collection. * @param {MessageReaction} reaction The reaction to possibly collect * @param {User} user The user that added the reaction - * @returns {Promise} + * @returns {?(Snowflake|string)} * @private */ - async collect(reaction, user) { + collect(reaction) { /** * Emitted whenever a reaction is collected. * @event ReactionCollector#collect @@ -93,18 +104,6 @@ class ReactionCollector extends Collector { */ if (reaction.message.id !== this.message.id) return null; - /** - * Emitted whenever a reaction is newly created on a message. Will emit only when a new reaction is - * added to the message, as opposed to {@link Collector#collect} which which will - * be emitted even when a reaction has already been added to the message. - * @event ReactionCollector#create - * @param {MessageReaction} reaction The reaction that was added - * @param {User} user The user that added the reaction - */ - if (reaction.count === 1 && (await this.filter(reaction, user, this.collected))) { - this.emit('create', reaction, user); - } - return ReactionCollector.key(reaction); } diff --git a/typings/index.d.ts b/typings/index.d.ts index ef7516e34f46..ef9bd1ffa709 100644 --- a/typings/index.d.ts +++ b/typings/index.d.ts @@ -1598,7 +1598,7 @@ export class ReactionCollector extends Collector; + public collect(reaction: MessageReaction, user: User): Snowflake | string | null; public dispose(reaction: MessageReaction, user: User): Snowflake | string | null; public empty(): void;