From 7d7ee8a04219b0c973866886b398ba9b037cc312 Mon Sep 17 00:00:00 2001 From: Vaporox Date: Sun, 27 Jun 2021 01:56:00 +0200 Subject: [PATCH] fix(Collector): docs and types --- .../MessageComponentInteractionCollector.js | 2 +- src/structures/ReactionCollector.js | 2 +- src/structures/interfaces/Collector.js | 4 +-- typings/index.d.ts | 26 +++++++++---------- 4 files changed, 17 insertions(+), 17 deletions(-) diff --git a/src/structures/MessageComponentInteractionCollector.js b/src/structures/MessageComponentInteractionCollector.js index e2b8841e5f0d..d59a52d727d7 100644 --- a/src/structures/MessageComponentInteractionCollector.js +++ b/src/structures/MessageComponentInteractionCollector.js @@ -82,7 +82,7 @@ class MessageComponentInteractionCollector extends Collector { /** * Handles an incoming interaction for possible collection. * @param {Interaction} interaction The interaction to possibly collect - * @returns {?(Snowflake|string)} + * @returns {?Snowflake} * @private */ collect(interaction) { diff --git a/src/structures/ReactionCollector.js b/src/structures/ReactionCollector.js index 149dd80a8e2d..d275dbc35e9f 100644 --- a/src/structures/ReactionCollector.js +++ b/src/structures/ReactionCollector.js @@ -81,7 +81,7 @@ 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 {Promise} * @private */ async collect(reaction, user) { diff --git a/src/structures/interfaces/Collector.js b/src/structures/interfaces/Collector.js index bce34f089bb1..ddd3e52ea9c2 100644 --- a/src/structures/interfaces/Collector.js +++ b/src/structures/interfaces/Collector.js @@ -95,7 +95,7 @@ class Collector extends EventEmitter { * @emits Collector#collect */ async handleCollect(...args) { - const collect = this.collect(...args); + const collect = await this.collect(...args); if (collect && (await this.filter(...args, this.collected))) { this.collected.set(collect, args[0]); @@ -269,7 +269,7 @@ class Collector extends EventEmitter { * be collected, or returns an object describing the data that should be stored. * @see Collector#handleCollect * @param {...*} args Any args the event listener emits - * @returns {?{key, value}} Data to insert into collection, if any + * @returns {?(*|Promise)} Data to insert into collection, if any * @abstract */ collect() {} diff --git a/typings/index.d.ts b/typings/index.d.ts index 125bbf5e3431..4ac843f401ef 100644 --- a/typings/index.d.ts +++ b/typings/index.d.ts @@ -480,8 +480,8 @@ declare module 'discord.js' { public adapters: Map; } - export abstract class Collector extends EventEmitter { - constructor(client: Client, options?: CollectorOptions<[V]>); + export abstract class Collector extends EventEmitter { + constructor(client: Client, options?: CollectorOptions<[V, ...F]>); private _timeout: NodeJS.Timeout | null; private _idletimeout: NodeJS.Timeout | null; @@ -489,9 +489,9 @@ declare module 'discord.js' { public collected: Collection; public ended: boolean; public abstract endReason: string | null; - public filter: CollectorFilter<[V]>; + public filter: CollectorFilter<[V, ...F]>; public readonly next: Promise; - public options: CollectorOptions<[V]>; + public options: CollectorOptions<[V, ...F]>; public checkEnd(): void; public handleCollect(...args: any[]): Promise; public handleDispose(...args: any[]): Promise; @@ -501,8 +501,8 @@ declare module 'discord.js' { public toJSON(): unknown; protected listener: (...args: any[]) => void; - public abstract collect(...args: any[]): K; - public abstract dispose(...args: any[]): K; + public abstract collect(...args: any[]): K | null | Promise; + public abstract dispose(...args: any[]): K | null; public on(event: 'collect' | 'dispose', listener: (...args: any[]) => Awaited): this; public on(event: 'end', listener: (collected: Collection, reason: string) => Awaited): this; @@ -1366,8 +1366,8 @@ declare module 'discord.js' { public options: MessageCollectorOptions; public received: number; - public collect(message: Message): Snowflake; - public dispose(message: Message): Snowflake; + public collect(message: Message): Snowflake | null; + public dispose(message: Message): Snowflake | null; } export class MessageComponentInteraction extends Interaction { @@ -1408,8 +1408,8 @@ declare module 'discord.js' { public total: number; public users: Collection; - public collect(interaction: Interaction): Snowflake; - public dispose(interaction: Interaction): Snowflake; + public collect(interaction: Interaction): Snowflake | null; + public dispose(interaction: Interaction): Snowflake | null; public on( event: 'collect' | 'dispose', listener: (interaction: MessageComponentInteraction) => Awaited, @@ -1616,7 +1616,7 @@ declare module 'discord.js' { public equals(presence: Presence): boolean; } - export class ReactionCollector extends Collector { + export class ReactionCollector extends Collector { constructor(message: Message, options?: ReactionCollectorOptions); private _handleChannelDeletion(channel: GuildChannel): void; private _handleGuildDeletion(guild: Guild): void; @@ -1630,8 +1630,8 @@ declare module 'discord.js' { public static key(reaction: MessageReaction): Snowflake | string; - public collect(reaction: MessageReaction): Promise; - public dispose(reaction: MessageReaction, user: User): Snowflake | string; + public collect(reaction: MessageReaction, user: User): Promise; + 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;