From 20075e306b18b376f9b1d0af4853ce662a31e0a0 Mon Sep 17 00:00:00 2001 From: SpaceEEC Date: Sun, 8 Mar 2020 19:33:18 +0100 Subject: [PATCH] fix(ReactionCollector): only modify users and total on collect (#3905) --- src/structures/ReactionCollector.js | 10 +++++++--- src/structures/interfaces/Collector.js | 8 ++++++++ 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/src/structures/ReactionCollector.js b/src/structures/ReactionCollector.js index b8c191afb..2b3235ef8 100644 --- a/src/structures/ReactionCollector.js +++ b/src/structures/ReactionCollector.js @@ -41,6 +41,11 @@ class ReactionCollector extends Collector { if (this.client.getMaxListeners() !== 0) this.client.setMaxListeners(this.client.getMaxListeners() + 1); this.client.on('messageReactionAdd', this.listener); + + this.on('fullCollect', (reaction, user) => { + this.users.set(user.id, user); + this.total++; + }); } /** @@ -64,9 +69,8 @@ class ReactionCollector extends Collector { * @returns {?string} Reason to end the collector, if any * @private */ - postCheck(reaction, user) { - this.users.set(user.id, user); - if (this.options.max && ++this.total >= this.options.max) return 'limit'; + postCheck() { + if (this.options.max && this.total >= this.options.max) return 'limit'; if (this.options.maxEmojis && this.collected.size >= this.options.maxEmojis) return 'emojiLimit'; if (this.options.maxUsers && this.users.size >= this.options.maxUsers) return 'userLimit'; return null; diff --git a/src/structures/interfaces/Collector.js b/src/structures/interfaces/Collector.js index 629ae2a94..6767b4279 100644 --- a/src/structures/interfaces/Collector.js +++ b/src/structures/interfaces/Collector.js @@ -99,6 +99,14 @@ class Collector extends EventEmitter { */ this.emit('collect', collect.value, this); + /** + * Emitted whenever an element is collected. + * @event Collector#fullCollect + * @param {...*} args The arguments emitted by the listener + * @private + */ + this.emit('fullCollect', ...args, this); + if (this._idletimeout) { this.client.clearTimeout(this._idletimeout); this._idletimeout = this.client.setTimeout(() => this.stop('idle'), this.options.idle);