mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-19 21:13:30 +01:00
fix: endReason not being properly set in base Collector (#7833)
* fix: `endReason` not being properly set in base Collector * types: add _endReason type
This commit is contained in:
@@ -197,7 +197,7 @@ class InteractionCollector extends Collector {
|
|||||||
if (this.options.max && this.total >= this.options.max) return 'limit';
|
if (this.options.max && this.total >= this.options.max) return 'limit';
|
||||||
if (this.options.maxComponents && this.collected.size >= this.options.maxComponents) return 'componentLimit';
|
if (this.options.maxComponents && this.collected.size >= this.options.maxComponents) return 'componentLimit';
|
||||||
if (this.options.maxUsers && this.users.size >= this.options.maxUsers) return 'userLimit';
|
if (this.options.maxUsers && this.users.size >= this.options.maxUsers) return 'userLimit';
|
||||||
return null;
|
return super.endReason;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -103,7 +103,7 @@ class MessageCollector extends Collector {
|
|||||||
get endReason() {
|
get endReason() {
|
||||||
if (this.options.max && this.collected.size >= this.options.max) return 'limit';
|
if (this.options.max && this.collected.size >= this.options.max) return 'limit';
|
||||||
if (this.options.maxProcessed && this.received === this.options.maxProcessed) return 'processedLimit';
|
if (this.options.maxProcessed && this.received === this.options.maxProcessed) return 'processedLimit';
|
||||||
return null;
|
return super.endReason;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -165,7 +165,7 @@ class ReactionCollector extends Collector {
|
|||||||
if (this.options.max && this.total >= this.options.max) return 'limit';
|
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.maxEmojis && this.collected.size >= this.options.maxEmojis) return 'emojiLimit';
|
||||||
if (this.options.maxUsers && this.users.size >= this.options.maxUsers) return 'userLimit';
|
if (this.options.maxUsers && this.users.size >= this.options.maxUsers) return 'userLimit';
|
||||||
return null;
|
return super.endReason;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -78,6 +78,13 @@ class Collector extends EventEmitter {
|
|||||||
*/
|
*/
|
||||||
this._idletimeout = null;
|
this._idletimeout = null;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The reason the collector ended
|
||||||
|
* @type {string|null}
|
||||||
|
* @private
|
||||||
|
*/
|
||||||
|
this._endReason = null;
|
||||||
|
|
||||||
if (typeof this.filter !== 'function') {
|
if (typeof this.filter !== 'function') {
|
||||||
throw new TypeError('INVALID_TYPE', 'options.filter', 'function');
|
throw new TypeError('INVALID_TYPE', 'options.filter', 'function');
|
||||||
}
|
}
|
||||||
@@ -187,6 +194,8 @@ class Collector extends EventEmitter {
|
|||||||
clearTimeout(this._idletimeout);
|
clearTimeout(this._idletimeout);
|
||||||
this._idletimeout = null;
|
this._idletimeout = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this._endReason = reason;
|
||||||
this.ended = true;
|
this.ended = true;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -270,9 +279,10 @@ class Collector extends EventEmitter {
|
|||||||
* The reason this collector has ended with, or null if it hasn't ended yet
|
* The reason this collector has ended with, or null if it hasn't ended yet
|
||||||
* @type {?string}
|
* @type {?string}
|
||||||
* @readonly
|
* @readonly
|
||||||
* @abstract
|
|
||||||
*/
|
*/
|
||||||
get endReason() {}
|
get endReason() {
|
||||||
|
return this._endReason;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Handles incoming events from the `handleCollect` function. Returns null if the event should not
|
* Handles incoming events from the `handleCollect` function. Returns null if the event should not
|
||||||
|
|||||||
6
packages/discord.js/typings/index.d.ts
vendored
6
packages/discord.js/typings/index.d.ts
vendored
@@ -875,11 +875,12 @@ export abstract class Collector<K, V, F extends unknown[] = []> extends EventEmi
|
|||||||
protected constructor(client: Client, options?: CollectorOptions<[V, ...F]>);
|
protected constructor(client: Client, options?: CollectorOptions<[V, ...F]>);
|
||||||
private _timeout: NodeJS.Timeout | null;
|
private _timeout: NodeJS.Timeout | null;
|
||||||
private _idletimeout: NodeJS.Timeout | null;
|
private _idletimeout: NodeJS.Timeout | null;
|
||||||
|
private _endReason: string | null;
|
||||||
|
|
||||||
public readonly client: Client;
|
public readonly client: Client;
|
||||||
public collected: Collection<K, V>;
|
public collected: Collection<K, V>;
|
||||||
public ended: boolean;
|
public ended: boolean;
|
||||||
public abstract get endReason(): string | null;
|
public get endReason(): string | null;
|
||||||
public filter: CollectorFilter<[V, ...F]>;
|
public filter: CollectorFilter<[V, ...F]>;
|
||||||
public get next(): Promise<V>;
|
public get next(): Promise<V>;
|
||||||
public options: CollectorOptions<[V, ...F]>;
|
public options: CollectorOptions<[V, ...F]>;
|
||||||
@@ -1552,7 +1553,6 @@ export class InteractionCollector<T extends Interaction> extends Collector<Snowf
|
|||||||
public channelId: Snowflake | null;
|
public channelId: Snowflake | null;
|
||||||
public messageInteractionId: Snowflake | null;
|
public messageInteractionId: Snowflake | null;
|
||||||
public componentType: ComponentType | null;
|
public componentType: ComponentType | null;
|
||||||
public get endReason(): string | null;
|
|
||||||
public guildId: Snowflake | null;
|
public guildId: Snowflake | null;
|
||||||
public interactionType: InteractionType | null;
|
public interactionType: InteractionType | null;
|
||||||
public messageId: Snowflake | null;
|
public messageId: Snowflake | null;
|
||||||
@@ -1767,7 +1767,6 @@ export class MessageCollector extends Collector<Snowflake, Message, [Collection<
|
|||||||
private _handleGuildDeletion(guild: Guild): void;
|
private _handleGuildDeletion(guild: Guild): void;
|
||||||
|
|
||||||
public channel: TextBasedChannel;
|
public channel: TextBasedChannel;
|
||||||
public get endReason(): string | null;
|
|
||||||
public options: MessageCollectorOptions;
|
public options: MessageCollectorOptions;
|
||||||
public received: number;
|
public received: number;
|
||||||
|
|
||||||
@@ -2016,7 +2015,6 @@ export class ReactionCollector extends Collector<Snowflake | string, MessageReac
|
|||||||
private _handleGuildDeletion(guild: Guild): void;
|
private _handleGuildDeletion(guild: Guild): void;
|
||||||
private _handleMessageDeletion(message: Message): void;
|
private _handleMessageDeletion(message: Message): void;
|
||||||
|
|
||||||
public get endReason(): string | null;
|
|
||||||
public message: Message;
|
public message: Message;
|
||||||
public options: ReactionCollectorOptions;
|
public options: ReactionCollectorOptions;
|
||||||
public total: number;
|
public total: number;
|
||||||
|
|||||||
Reference in New Issue
Block a user