mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-09 16:13:31 +01:00
feat(Collector): add ignore event (#7644)
Co-authored-by: Parbez <imranbarbhuiya.fsd@gmail.com>
This commit is contained in:
@@ -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();
|
||||
|
||||
15
packages/discord.js/typings/index.d.ts
vendored
15
packages/discord.js/typings/index.d.ts
vendored
@@ -873,6 +873,7 @@ export { Collection } from '@discordjs/collection';
|
||||
|
||||
export interface CollectorEventTypes<K, V, F extends unknown[] = []> {
|
||||
collect: [V, ...F];
|
||||
ignore: [V, ...F];
|
||||
dispose: [V, ...F];
|
||||
end: [collected: Collection<K, V>, reason: string];
|
||||
}
|
||||
@@ -1522,11 +1523,11 @@ export class InteractionCollector<T extends Interaction> extends Collector<Snowf
|
||||
public collect(interaction: Interaction): Snowflake;
|
||||
public empty(): void;
|
||||
public dispose(interaction: Interaction): Snowflake;
|
||||
public on(event: 'collect' | 'dispose', listener: (interaction: T) => Awaitable<void>): this;
|
||||
public on(event: 'collect' | 'dispose' | 'ignore', listener: (interaction: T) => Awaitable<void>): this;
|
||||
public on(event: 'end', listener: (collected: Collection<Snowflake, T>, reason: string) => Awaitable<void>): this;
|
||||
public on(event: string, listener: (...args: any[]) => Awaitable<void>): this;
|
||||
|
||||
public once(event: 'collect' | 'dispose', listener: (interaction: T) => Awaitable<void>): this;
|
||||
public once(event: 'collect' | 'dispose' | 'ignore', listener: (interaction: T) => Awaitable<void>): this;
|
||||
public once(event: 'end', listener: (collected: Collection<Snowflake, T>, reason: string) => Awaitable<void>): this;
|
||||
public once(event: string, listener: (...args: any[]) => Awaitable<void>): this;
|
||||
}
|
||||
@@ -2024,11 +2025,17 @@ export class ReactionCollector extends Collector<Snowflake | string, MessageReac
|
||||
public dispose(reaction: MessageReaction, user: User): Snowflake | string | null;
|
||||
public empty(): void;
|
||||
|
||||
public on(event: 'collect' | 'dispose' | 'remove', listener: (reaction: MessageReaction, user: User) => void): this;
|
||||
public on(
|
||||
event: 'collect' | 'dispose' | 'remove' | 'ignore',
|
||||
listener: (reaction: MessageReaction, user: User) => void,
|
||||
): this;
|
||||
public on(event: 'end', listener: (collected: Collection<Snowflake, MessageReaction>, 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<Snowflake, MessageReaction>, reason: string) => void,
|
||||
|
||||
Reference in New Issue
Block a user