diff --git a/packages/discord.js/src/structures/interfaces/Collector.js b/packages/discord.js/src/structures/interfaces/Collector.js index c700cf64e..ed82fa533 100644 --- a/packages/discord.js/src/structures/interfaces/Collector.js +++ b/packages/discord.js/src/structures/interfaces/Collector.js @@ -103,21 +103,31 @@ class Collector extends EventEmitter { * @emits Collector#collect */ async handleCollect(...args) { - const collect = await this.collect(...args); + const collectedId = await this.collect(...args); - if (collect && (await this.filter(...args, this.collected))) { - this.collected.set(collect, args[0]); + if (collectedId) { + const filterResult = await this.filter(...args, this.collected); + if (filterResult) { + this.collected.set(collectedId, args[0]); - /** - * Emitted whenever an element is collected. - * @event Collector#collect - * @param {...*} args The arguments emitted by the listener - */ - this.emit('collect', ...args); + /** + * Emitted whenever an element is collected. + * @event Collector#collect + * @param {...*} args The arguments emitted by the listener + */ + this.emit('collect', ...args); - if (this._idletimeout) { - clearTimeout(this._idletimeout); - this._idletimeout = setTimeout(() => this.stop('idle'), this.options.idle).unref(); + if (this._idletimeout) { + clearTimeout(this._idletimeout); + this._idletimeout = setTimeout(() => this.stop('idle'), this.options.idle).unref(); + } + } else { + /** + * Emitted whenever an element is not collected by the collector. + * @event Collector#ignore + * @param {...*} args The arguments emitted by the listener + */ + this.emit('ignore', ...args); } } this.checkEnd(); diff --git a/packages/discord.js/typings/index.d.ts b/packages/discord.js/typings/index.d.ts index 667bd1744..509473eb8 100644 --- a/packages/discord.js/typings/index.d.ts +++ b/packages/discord.js/typings/index.d.ts @@ -873,6 +873,7 @@ export { Collection } from '@discordjs/collection'; export interface CollectorEventTypes { collect: [V, ...F]; + ignore: [V, ...F]; dispose: [V, ...F]; end: [collected: Collection, reason: string]; } @@ -1522,11 +1523,11 @@ export class InteractionCollector extends Collector Awaitable): this; + public on(event: 'collect' | 'dispose' | 'ignore', listener: (interaction: T) => Awaitable): this; public on(event: 'end', listener: (collected: Collection, reason: string) => Awaitable): this; public on(event: string, listener: (...args: any[]) => Awaitable): this; - public once(event: 'collect' | 'dispose', listener: (interaction: T) => Awaitable): this; + public once(event: 'collect' | 'dispose' | 'ignore', listener: (interaction: T) => Awaitable): this; public once(event: 'end', listener: (collected: Collection, reason: string) => Awaitable): this; public once(event: string, listener: (...args: any[]) => Awaitable): this; } @@ -2024,11 +2025,17 @@ export class ReactionCollector extends Collector void): this; + public on( + event: 'collect' | 'dispose' | 'remove' | 'ignore', + listener: (reaction: MessageReaction, user: User) => void, + ): this; public on(event: 'end', listener: (collected: Collection, reason: string) => void): this; public on(event: string, listener: (...args: any[]) => void): this; - public once(event: 'collect' | 'dispose' | 'remove', listener: (reaction: MessageReaction, user: User) => void): this; + public once( + event: 'collect' | 'dispose' | 'remove' | 'ignore', + listener: (reaction: MessageReaction, user: User) => void, + ): this; public once( event: 'end', listener: (collected: Collection, reason: string) => void,