refactor(Collector): make filter an option (#5903)

Co-authored-by: SpaceEEC <spaceeec@yahoo.com>
This commit is contained in:
Jan
2021-06-26 11:57:06 +02:00
committed by GitHub
parent 1439183ad3
commit 0d0c8f07f2
7 changed files with 61 additions and 83 deletions

View File

@@ -399,18 +399,17 @@ class Message extends Base {
/** /**
* Creates a reaction collector. * Creates a reaction collector.
* @param {CollectorFilter} filter The filter to apply
* @param {ReactionCollectorOptions} [options={}] Options to send to the collector * @param {ReactionCollectorOptions} [options={}] Options to send to the collector
* @returns {ReactionCollector} * @returns {ReactionCollector}
* @example * @example
* // Create a reaction collector * // Create a reaction collector
* const filter = (reaction, user) => reaction.emoji.name === '👌' && user.id === 'someID'; * const filter = (reaction, user) => reaction.emoji.name === '👌' && user.id === 'someID';
* const collector = message.createReactionCollector(filter, { time: 15000 }); * const collector = message.createReactionCollector({ filter, time: 15000 });
* collector.on('collect', r => console.log(`Collected ${r.emoji.name}`)); * collector.on('collect', r => console.log(`Collected ${r.emoji.name}`));
* collector.on('end', collected => console.log(`Collected ${collected.size} items`)); * collector.on('end', collected => console.log(`Collected ${collected.size} items`));
*/ */
createReactionCollector(filter, options = {}) { createReactionCollector(options = {}) {
return new ReactionCollector(this, filter, options); return new ReactionCollector(this, options);
} }
/** /**
@@ -422,19 +421,18 @@ class Message extends Base {
/** /**
* Similar to createReactionCollector but in promise form. * Similar to createReactionCollector but in promise form.
* Resolves with a collection of reactions that pass the specified filter. * Resolves with a collection of reactions that pass the specified filter.
* @param {CollectorFilter} filter The filter function to use
* @param {AwaitReactionsOptions} [options={}] Optional options to pass to the internal collector * @param {AwaitReactionsOptions} [options={}] Optional options to pass to the internal collector
* @returns {Promise<Collection<string, MessageReaction>>} * @returns {Promise<Collection<string, MessageReaction>>}
* @example * @example
* // Create a reaction collector * // Create a reaction collector
* const filter = (reaction, user) => reaction.emoji.name === '👌' && user.id === 'someID' * const filter = (reaction, user) => reaction.emoji.name === '👌' && user.id === 'someID'
* message.awaitReactions(filter, { time: 15000 }) * message.awaitReactions({ filter, time: 15000 })
* .then(collected => console.log(`Collected ${collected.size} reactions`)) * .then(collected => console.log(`Collected ${collected.size} reactions`))
* .catch(console.error); * .catch(console.error);
*/ */
awaitReactions(filter, options = {}) { awaitReactions(options = {}) {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
const collector = this.createReactionCollector(filter, options); const collector = this.createReactionCollector(options);
collector.once('end', (reactions, reason) => { collector.once('end', (reactions, reason) => {
if (options.errors && options.errors.includes(reason)) reject(reactions); if (options.errors && options.errors.includes(reason)) reject(reactions);
else resolve(reactions); else resolve(reactions);
@@ -444,42 +442,41 @@ class Message extends Base {
/** /**
* Creates a message component interaction collector. * Creates a message component interaction collector.
* @param {CollectorFilter} filter The filter to apply
* @param {MessageComponentInteractionCollectorOptions} [options={}] Options to send to the collector * @param {MessageComponentInteractionCollectorOptions} [options={}] Options to send to the collector
* @returns {MessageComponentInteractionCollector} * @returns {MessageComponentInteractionCollector}
* @example * @example
* // Create a message component interaction collector * // Create a message component interaction collector
* const filter = (interaction) => interaction.customID === 'button' && interaction.user.id === 'someID'; * const filter = (interaction) => interaction.customID === 'button' && interaction.user.id === 'someID';
* const collector = message.createMessageComponentInteractionCollector(filter, { time: 15000 }); * const collector = message.createMessageComponentInteractionCollector({ filter, time: 15000 });
* collector.on('collect', i => console.log(`Collected ${i.customID}`)); * collector.on('collect', i => console.log(`Collected ${i.customID}`));
* collector.on('end', collected => console.log(`Collected ${collected.size} items`)); * collector.on('end', collected => console.log(`Collected ${collected.size} items`));
*/ */
createMessageComponentInteractionCollector(filter, options = {}) { createMessageComponentInteractionCollector(options = {}) {
return new MessageComponentInteractionCollector(this, filter, options); return new MessageComponentInteractionCollector(this, options);
} }
/** /**
* An object containing the same properties as CollectorOptions, but a few more: * An object containing the same properties as CollectorOptions, but a few more:
* @typedef {Object} AwaitMessageComponentInteractionOptions * @typedef {Object} AwaitMessageComponentInteractionOptions
* @property {CollectorFilter} [filter] The filter applied to this collector
* @property {number} [time] Time to wait for an interaction before rejecting * @property {number} [time] Time to wait for an interaction before rejecting
*/ */
/** /**
* Collects a single component interaction that passes the filter. * Collects a single component interaction that passes the filter.
* The Promise will reject if the time expires. * The Promise will reject if the time expires.
* @param {CollectorFilter} filter The filter function to use
* @param {AwaitMessageComponentInteractionOptions} [options={}] Options to pass to the internal collector * @param {AwaitMessageComponentInteractionOptions} [options={}] Options to pass to the internal collector
* @returns {Promise<MessageComponentInteraction>} * @returns {Promise<MessageComponentInteraction>}
* @example * @example
* // Collect a message component interaction * // Collect a message component interaction
* const filter = (interaction) => interaction.customID === 'button' && interaction.user.id === 'someID'; * const filter = (interaction) => interaction.customID === 'button' && interaction.user.id === 'someID';
* message.awaitMessageComponentInteraction(filter, { time: 15000 }) * message.awaitMessageComponentInteraction({ filter, time: 15000 })
* .then(interaction => console.log(`${interaction.customID} was clicked!`)) * .then(interaction => console.log(`${interaction.customID} was clicked!`))
* .catch(console.error); * .catch(console.error);
*/ */
awaitMessageComponentInteraction(filter, { time } = {}) { awaitMessageComponentInteraction(options = {}) {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
const collector = this.createMessageComponentInteractionCollector(filter, { max: 1, time }); const collector = this.createMessageComponentInteractionCollector({ ...options, max: 1 });
collector.once('end', (interactions, reason) => { collector.once('end', (interactions, reason) => {
const interaction = interactions.first(); const interaction = interactions.first();
if (interaction) resolve(interaction); if (interaction) resolve(interaction);

View File

@@ -17,12 +17,11 @@ const { Events } = require('../util/Constants');
class MessageCollector extends Collector { class MessageCollector extends Collector {
/** /**
* @param {TextChannel|DMChannel} channel The channel * @param {TextChannel|DMChannel} channel The channel
* @param {CollectorFilter} filter The filter to be applied to this collector
* @param {MessageCollectorOptions} options The options to be applied to this collector * @param {MessageCollectorOptions} options The options to be applied to this collector
* @emits MessageCollector#message * @emits MessageCollector#message
*/ */
constructor(channel, filter, options = {}) { constructor(channel, options = {}) {
super(channel.client, filter, options); super(channel.client, options);
/** /**
* The channel * The channel

View File

@@ -21,11 +21,10 @@ class MessageComponentInteractionCollector extends Collector {
/** /**
* @param {Message|TextChannel|DMChannel|NewsChannel} source * @param {Message|TextChannel|DMChannel|NewsChannel} source
* The source from which to collect message component interactions * The source from which to collect message component interactions
* @param {CollectorFilter} filter The filter to apply to this collector
* @param {MessageComponentInteractionCollectorOptions} [options={}] The options to apply to this collector * @param {MessageComponentInteractionCollectorOptions} [options={}] The options to apply to this collector
*/ */
constructor(source, filter, options = {}) { constructor(source, options = {}) {
super(source.client, filter, options); super(source.client, options);
/** /**
* The message from which to collect message component interactions, if provided * The message from which to collect message component interactions, if provided

View File

@@ -20,11 +20,10 @@ const { Events } = require('../util/Constants');
class ReactionCollector extends Collector { class ReactionCollector extends Collector {
/** /**
* @param {Message} message The message upon which to collect reactions * @param {Message} message The message upon which to collect reactions
* @param {CollectorFilter} filter The filter to apply to this collector
* @param {ReactionCollectorOptions} [options={}] The options to apply to this collector * @param {ReactionCollectorOptions} [options={}] The options to apply to this collector
*/ */
constructor(message, filter, options = {}) { constructor(message, options = {}) {
super(message.client, filter, options); super(message.client, options);
/** /**
* The message upon which to collect reactions * The message upon which to collect reactions
@@ -82,10 +81,10 @@ class ReactionCollector extends Collector {
* Handles an incoming reaction for possible collection. * Handles an incoming reaction for possible collection.
* @param {MessageReaction} reaction The reaction to possibly collect * @param {MessageReaction} reaction The reaction to possibly collect
* @param {User} user The user that added the reaction * @param {User} user The user that added the reaction
* @returns {?(Snowflake|string)} * @returns {Promise<Snowflake|string>}
* @private * @private
*/ */
collect(reaction, user) { async collect(reaction, user) {
/** /**
* Emitted whenever a reaction is collected. * Emitted whenever a reaction is collected.
* @event ReactionCollector#collect * @event ReactionCollector#collect
@@ -102,7 +101,7 @@ class ReactionCollector extends Collector {
* @param {MessageReaction} reaction The reaction that was added * @param {MessageReaction} reaction The reaction that was added
* @param {User} user The user that added the reaction * @param {User} user The user that added the reaction
*/ */
if (reaction.count === 1 && this.filter(reaction, user, this.collected)) { if (reaction.count === 1 && (await this.filter(reaction, user, this.collected))) {
this.emit('create', reaction, user); this.emit('create', reaction, user);
} }

View File

@@ -16,6 +16,7 @@ const Util = require('../../util/Util');
/** /**
* Options to be applied to the collector. * Options to be applied to the collector.
* @typedef {Object} CollectorOptions * @typedef {Object} CollectorOptions
* @property {CollectorFilter} [filter] The filter applied to this collector
* @property {number} [time] How long to run the collector for in milliseconds * @property {number} [time] How long to run the collector for in milliseconds
* @property {number} [idle] How long to stop the collector after inactivity in milliseconds * @property {number} [idle] How long to stop the collector after inactivity in milliseconds
* @property {boolean} [dispose=false] Whether to dispose data when it's deleted * @property {boolean} [dispose=false] Whether to dispose data when it's deleted
@@ -26,7 +27,7 @@ const Util = require('../../util/Util');
* @abstract * @abstract
*/ */
class Collector extends EventEmitter { class Collector extends EventEmitter {
constructor(client, filter, options = {}) { constructor(client, options = {}) {
super(); super();
/** /**
@@ -40,8 +41,9 @@ class Collector extends EventEmitter {
/** /**
* The filter applied to this collector * The filter applied to this collector
* @type {CollectorFilter} * @type {CollectorFilter}
* @returns {boolean|Promise<boolean>}
*/ */
this.filter = filter; this.filter = options.filter ?? (() => true);
/** /**
* The options of this collector * The options of this collector
@@ -75,8 +77,8 @@ class Collector extends EventEmitter {
*/ */
this._idletimeout = null; this._idletimeout = null;
if (typeof filter !== 'function') { if (typeof this.filter !== 'function') {
throw new TypeError('INVALID_TYPE', 'filter', 'function'); throw new TypeError('INVALID_TYPE', 'options.filter', 'function');
} }
this.handleCollect = this.handleCollect.bind(this); this.handleCollect = this.handleCollect.bind(this);
@@ -89,6 +91,7 @@ class Collector extends EventEmitter {
/** /**
* Call this to handle an event as a collectable element. Accepts any event data as parameters. * Call this to handle an event as a collectable element. Accepts any event data as parameters.
* @param {...*} args The arguments emitted by the listener * @param {...*} args The arguments emitted by the listener
* @returns {Promise<void>}
* @emits Collector#collect * @emits Collector#collect
*/ */
async handleCollect(...args) { async handleCollect(...args) {
@@ -115,13 +118,14 @@ class Collector extends EventEmitter {
/** /**
* Call this to remove an element from the collection. Accepts any event data as parameters. * Call this to remove an element from the collection. Accepts any event data as parameters.
* @param {...*} args The arguments emitted by the listener * @param {...*} args The arguments emitted by the listener
* @returns {Promise<void>}
* @emits Collector#dispose * @emits Collector#dispose
*/ */
handleDispose(...args) { async handleDispose(...args) {
if (!this.options.dispose) return; if (!this.options.dispose) return;
const dispose = this.dispose(...args); const dispose = this.dispose(...args);
if (!dispose || !this.filter(...args) || !this.collected.has(dispose)) return; if (!dispose || !(await this.filter(...args)) || !this.collected.has(dispose)) return;
this.collected.delete(dispose); this.collected.delete(dispose);
/** /**

View File

@@ -275,18 +275,17 @@ class TextBasedChannel {
/** /**
* Creates a Message Collector. * Creates a Message Collector.
* @param {CollectorFilter} filter The filter to create the collector with
* @param {MessageCollectorOptions} [options={}] The options to pass to the collector * @param {MessageCollectorOptions} [options={}] The options to pass to the collector
* @returns {MessageCollector} * @returns {MessageCollector}
* @example * @example
* // Create a message collector * // Create a message collector
* const filter = m => m.content.includes('discord'); * const filter = m => m.content.includes('discord');
* const collector = channel.createMessageCollector(filter, { time: 15000 }); * const collector = channel.createMessageCollector({ filter, time: 15000 });
* collector.on('collect', m => console.log(`Collected ${m.content}`)); * collector.on('collect', m => console.log(`Collected ${m.content}`));
* collector.on('end', collected => console.log(`Collected ${collected.size} items`)); * collector.on('end', collected => console.log(`Collected ${collected.size} items`));
*/ */
createMessageCollector(filter, options = {}) { createMessageCollector(options = {}) {
return new MessageCollector(this, filter, options); return new MessageCollector(this, options);
} }
/** /**
@@ -298,20 +297,19 @@ class TextBasedChannel {
/** /**
* Similar to createMessageCollector but in promise form. * Similar to createMessageCollector but in promise form.
* Resolves with a collection of messages that pass the specified filter. * Resolves with a collection of messages that pass the specified filter.
* @param {CollectorFilter} filter The filter function to use
* @param {AwaitMessagesOptions} [options={}] Optional options to pass to the internal collector * @param {AwaitMessagesOptions} [options={}] Optional options to pass to the internal collector
* @returns {Promise<Collection<Snowflake, Message>>} * @returns {Promise<Collection<Snowflake, Message>>}
* @example * @example
* // Await !vote messages * // Await !vote messages
* const filter = m => m.content.startsWith('!vote'); * const filter = m => m.content.startsWith('!vote');
* // Errors: ['time'] treats ending because of the time limit as an error * // Errors: ['time'] treats ending because of the time limit as an error
* channel.awaitMessages(filter, { max: 4, time: 60000, errors: ['time'] }) * channel.awaitMessages({ filter, max: 4, time: 60000, errors: ['time'] })
* .then(collected => console.log(collected.size)) * .then(collected => console.log(collected.size))
* .catch(collected => console.log(`After a minute, only ${collected.size} out of 4 voted.`)); * .catch(collected => console.log(`After a minute, only ${collected.size} out of 4 voted.`));
*/ */
awaitMessages(filter, options = {}) { awaitMessages(options = {}) {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
const collector = this.createMessageCollector(filter, options); const collector = this.createMessageCollector(options);
collector.once('end', (collection, reason) => { collector.once('end', (collection, reason) => {
if (options.errors && options.errors.includes(reason)) { if (options.errors && options.errors.includes(reason)) {
reject(collection); reject(collection);
@@ -324,36 +322,34 @@ class TextBasedChannel {
/** /**
* Creates a button interaction collector. * Creates a button interaction collector.
* @param {CollectorFilter} filter The filter to apply
* @param {MessageComponentInteractionCollectorOptions} [options={}] Options to send to the collector * @param {MessageComponentInteractionCollectorOptions} [options={}] Options to send to the collector
* @returns {MessageComponentInteractionCollector} * @returns {MessageComponentInteractionCollector}
* @example * @example
* // Create a button interaction collector * // Create a button interaction collector
* const filter = (interaction) => interaction.customID === 'button' && interaction.user.id === 'someID'; * const filter = (interaction) => interaction.customID === 'button' && interaction.user.id === 'someID';
* const collector = channel.createMessageComponentInteractionCollector(filter, { time: 15000 }); * const collector = channel.createMessageComponentInteractionCollector({ filter, time: 15000 });
* collector.on('collect', i => console.log(`Collected ${i.customID}`)); * collector.on('collect', i => console.log(`Collected ${i.customID}`));
* collector.on('end', collected => console.log(`Collected ${collected.size} items`)); * collector.on('end', collected => console.log(`Collected ${collected.size} items`));
*/ */
createMessageComponentInteractionCollector(filter, options = {}) { createMessageComponentInteractionCollector(options = {}) {
return new MessageComponentInteractionCollector(this, filter, options); return new MessageComponentInteractionCollector(this, options);
} }
/** /**
* Collects a single component interaction that passes the filter. * Collects a single component interaction that passes the filter.
* The Promise will reject if the time expires. * The Promise will reject if the time expires.
* @param {CollectorFilter} filter The filter function to use
* @param {AwaitMessageComponentInteractionOptions} [options={}] Options to pass to the internal collector * @param {AwaitMessageComponentInteractionOptions} [options={}] Options to pass to the internal collector
* @returns {Promise<MessageComponentInteraction>} * @returns {Promise<MessageComponentInteraction>}
* @example * @example
* // Collect a message component interaction * // Collect a message component interaction
* const filter = (interaction) => interaction.customID === 'button' && interaction.user.id === 'someID'; * const filter = (interaction) => interaction.customID === 'button' && interaction.user.id === 'someID';
* channel.awaitMessageComponentInteraction(filter, { time: 15000 }) * channel.awaitMessageComponentInteraction({ filter, time: 15000 })
* .then(interaction => console.log(`${interaction.customID} was clicked!`)) * .then(interaction => console.log(`${interaction.customID} was clicked!`))
* .catch(console.error); * .catch(console.error);
*/ */
awaitMessageComponentInteraction(filter, { time } = {}) { awaitMessageComponentInteraction(options = {}) {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
const collector = this.createMessageComponentInteractionCollector(filter, { max: 1, time }); const collector = this.createMessageComponentInteractionCollector({ ...options, max: 1 });
collector.once('end', (interactions, reason) => { collector.once('end', (interactions, reason) => {
const interaction = interactions.first(); const interaction = interactions.first();
if (interaction) resolve(interaction); if (interaction) resolve(interaction);

50
typings/index.d.ts vendored
View File

@@ -482,7 +482,7 @@ declare module 'discord.js' {
} }
export abstract class Collector<K, V> extends EventEmitter { export abstract class Collector<K, V> extends EventEmitter {
constructor(client: Client, filter: CollectorFilter<[V]>, options?: CollectorOptions); constructor(client: Client, options?: CollectorOptions<[V]>);
private _timeout: NodeJS.Timeout | null; private _timeout: NodeJS.Timeout | null;
private _idletimeout: NodeJS.Timeout | null; private _idletimeout: NodeJS.Timeout | null;
@@ -492,10 +492,10 @@ declare module 'discord.js' {
public abstract endReason: string | null; public abstract endReason: string | null;
public filter: CollectorFilter<[V]>; public filter: CollectorFilter<[V]>;
public readonly next: Promise<V>; public readonly next: Promise<V>;
public options: CollectorOptions; public options: CollectorOptions<[V]>;
public checkEnd(): void; public checkEnd(): void;
public handleCollect(...args: any[]): void; public handleCollect(...args: any[]): Promise<void>;
public handleDispose(...args: any[]): void; public handleDispose(...args: any[]): Promise<void>;
public stop(reason?: string): void; public stop(reason?: string): void;
public resetTimer(options?: CollectorResetTimerOptions): void; public resetTimer(options?: CollectorResetTimerOptions): void;
public [Symbol.asyncIterator](): AsyncIterableIterator<V>; public [Symbol.asyncIterator](): AsyncIterableIterator<V>;
@@ -1281,19 +1281,11 @@ declare module 'discord.js' {
public flags: Readonly<MessageFlags>; public flags: Readonly<MessageFlags>;
public reference: MessageReference | null; public reference: MessageReference | null;
public awaitMessageComponentInteraction( public awaitMessageComponentInteraction(
filter: CollectorFilter<[MessageComponentInteraction]>,
options?: AwaitMessageComponentInteractionOptions, options?: AwaitMessageComponentInteractionOptions,
): Promise<MessageComponentInteraction>; ): Promise<MessageComponentInteraction>;
public awaitReactions( public awaitReactions(options?: AwaitReactionsOptions): Promise<Collection<Snowflake | string, MessageReaction>>;
filter: CollectorFilter<[MessageReaction, User]>, public createReactionCollector(options?: ReactionCollectorOptions): ReactionCollector;
options?: AwaitReactionsOptions,
): Promise<Collection<Snowflake | string, MessageReaction>>;
public createReactionCollector(
filter: CollectorFilter<[MessageReaction, User]>,
options?: ReactionCollectorOptions,
): ReactionCollector;
public createMessageComponentInteractionCollector( public createMessageComponentInteractionCollector(
filter: CollectorFilter<[MessageComponentInteraction]>,
options?: MessageComponentInteractionCollectorOptions, options?: MessageComponentInteractionCollectorOptions,
): MessageComponentInteractionCollector; ): MessageComponentInteractionCollector;
public delete(): Promise<Message>; public delete(): Promise<Message>;
@@ -1372,11 +1364,7 @@ declare module 'discord.js' {
} }
export class MessageCollector extends Collector<Snowflake, Message> { export class MessageCollector extends Collector<Snowflake, Message> {
constructor( constructor(channel: TextChannel | DMChannel, options?: MessageCollectorOptions);
channel: TextChannel | DMChannel,
filter: CollectorFilter<[Message]>,
options?: MessageCollectorOptions,
);
private _handleChannelDeletion(channel: GuildChannel): void; private _handleChannelDeletion(channel: GuildChannel): void;
private _handleGuildDeletion(guild: Guild): void; private _handleGuildDeletion(guild: Guild): void;
@@ -1413,7 +1401,6 @@ declare module 'discord.js' {
export class MessageComponentInteractionCollector extends Collector<Snowflake, MessageComponentInteraction> { export class MessageComponentInteractionCollector extends Collector<Snowflake, MessageComponentInteraction> {
constructor( constructor(
source: Message | TextChannel | NewsChannel | DMChannel, source: Message | TextChannel | NewsChannel | DMChannel,
filter: CollectorFilter<[MessageComponentInteraction]>,
options?: MessageComponentInteractionCollectorOptions, options?: MessageComponentInteractionCollectorOptions,
); );
private _handleMessageDeletion(message: Message): void; private _handleMessageDeletion(message: Message): void;
@@ -1637,7 +1624,7 @@ declare module 'discord.js' {
} }
export class ReactionCollector extends Collector<Snowflake | string, MessageReaction> { export class ReactionCollector extends Collector<Snowflake | string, MessageReaction> {
constructor(message: Message, filter: CollectorFilter<[MessageReaction, User]>, options?: ReactionCollectorOptions); constructor(message: Message, options?: ReactionCollectorOptions);
private _handleChannelDeletion(channel: GuildChannel): void; private _handleChannelDeletion(channel: GuildChannel): void;
private _handleGuildDeletion(guild: Guild): void; private _handleGuildDeletion(guild: Guild): void;
private _handleMessageDeletion(message: Message): void; private _handleMessageDeletion(message: Message): void;
@@ -1650,7 +1637,7 @@ declare module 'discord.js' {
public static key(reaction: MessageReaction): Snowflake | string; public static key(reaction: MessageReaction): Snowflake | string;
public collect(reaction: MessageReaction): Snowflake | string; public collect(reaction: MessageReaction): Promise<Snowflake | string>;
public dispose(reaction: MessageReaction, user: User): Snowflake | string; public dispose(reaction: MessageReaction, user: User): Snowflake | string;
public empty(): void; public empty(): void;
@@ -2619,22 +2606,17 @@ declare module 'discord.js' {
typing: boolean; typing: boolean;
typingCount: number; typingCount: number;
awaitMessageComponentInteraction( awaitMessageComponentInteraction(
filter: CollectorFilter<[MessageComponentInteraction]>,
options?: AwaitMessageComponentInteractionOptions, options?: AwaitMessageComponentInteractionOptions,
): Promise<MessageComponentInteraction>; ): Promise<MessageComponentInteraction>;
awaitMessages( awaitMessages(options?: AwaitMessagesOptions): Promise<Collection<Snowflake, Message>>;
filter: CollectorFilter<[Message]>,
options?: AwaitMessagesOptions,
): Promise<Collection<Snowflake, Message>>;
bulkDelete( bulkDelete(
messages: Collection<Snowflake, Message> | readonly MessageResolvable[] | number, messages: Collection<Snowflake, Message> | readonly MessageResolvable[] | number,
filterOld?: boolean, filterOld?: boolean,
): Promise<Collection<Snowflake, Message>>; ): Promise<Collection<Snowflake, Message>>;
createMessageComponentInteractionCollector( createMessageComponentInteractionCollector(
filter: CollectorFilter<[MessageComponentInteraction]>,
options?: MessageComponentInteractionCollectorOptions, options?: MessageComponentInteractionCollectorOptions,
): MessageComponentInteractionCollector; ): MessageComponentInteractionCollector;
createMessageCollector(filter: CollectorFilter<[Message]>, options?: MessageCollectorOptions): MessageCollector; createMessageCollector(options?: MessageCollectorOptions): MessageCollector;
startTyping(count?: number): Promise<void>; startTyping(count?: number): Promise<void>;
stopTyping(force?: boolean): void; stopTyping(force?: boolean): void;
} }
@@ -2873,6 +2855,7 @@ declare module 'discord.js' {
} }
interface AwaitMessageComponentInteractionOptions { interface AwaitMessageComponentInteractionOptions {
filter?: CollectorFilter<[MessageComponentInteraction]>;
time?: number; time?: number;
} }
@@ -3070,7 +3053,8 @@ declare module 'discord.js' {
type CollectorFilter<T extends any[]> = (...args: T) => boolean | Promise<boolean>; type CollectorFilter<T extends any[]> = (...args: T) => boolean | Promise<boolean>;
interface CollectorOptions { interface CollectorOptions<T extends any[]> {
filter?: CollectorFilter<T>;
time?: number; time?: number;
idle?: number; idle?: number;
dispose?: boolean; dispose?: boolean;
@@ -3641,14 +3625,14 @@ declare module 'discord.js' {
type MessageButtonStyleResolvable = MessageButtonStyle | MessageButtonStyles; type MessageButtonStyleResolvable = MessageButtonStyle | MessageButtonStyles;
interface MessageCollectorOptions extends CollectorOptions { interface MessageCollectorOptions extends CollectorOptions<[Message]> {
max?: number; max?: number;
maxProcessed?: number; maxProcessed?: number;
} }
type MessageComponent = BaseMessageComponent | MessageActionRow | MessageButton | MessageSelectMenu; type MessageComponent = BaseMessageComponent | MessageActionRow | MessageButton | MessageSelectMenu;
interface MessageComponentInteractionCollectorOptions extends CollectorOptions { interface MessageComponentInteractionCollectorOptions extends CollectorOptions<[MessageComponentInteraction]> {
max?: number; max?: number;
maxComponents?: number; maxComponents?: number;
maxUsers?: number; maxUsers?: number;
@@ -4082,7 +4066,7 @@ declare module 'discord.js' {
remainingTime: number; remainingTime: number;
} }
interface ReactionCollectorOptions extends CollectorOptions { interface ReactionCollectorOptions extends CollectorOptions<[MessageReaction, User]> {
max?: number; max?: number;
maxEmojis?: number; maxEmojis?: number;
maxUsers?: number; maxUsers?: number;