From 738e747a60f0763f96dc575fb11fe9dfec1f7a3a Mon Sep 17 00:00:00 2001 From: SpaceEEC Date: Fri, 1 Oct 2021 20:01:35 +0200 Subject: [PATCH 1/2] fix(ReactionCollector): only call the filter function once --- src/structures/ReactionCollector.js | 27 +++++++++++++-------------- 1 file changed, 13 insertions(+), 14 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); } From 56f1597ee4fe820975e5bf4132bcc8af3f30da77 Mon Sep 17 00:00:00 2001 From: SpaceEEC Date: Fri, 1 Oct 2021 20:38:11 +0200 Subject: [PATCH 2/2] types(ReactionCollector): collect is now sync --- typings/index.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/typings/index.d.ts b/typings/index.d.ts index bb8e8293e706..fd50f603c0dc 100644 --- a/typings/index.d.ts +++ b/typings/index.d.ts @@ -1572,7 +1572,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;