discord.js-collector-utils
Version:
Collector utilities for discord.js.
94 lines (93 loc) • 4.46 kB
TypeScript
import { ButtonInteraction, Message, MessageReaction, ModalBuilder, ModalSubmitInteraction, SelectMenuInteraction, TextBasedChannel, User } from 'discord.js';
export declare class CollectorUtils {
/**
* Collect a response by buttons.
* @param message Message to collect button interactions on.
* @param retriever Method which takes a collected button interaction and returns a desired result, or `undefined` if invalid.
* @param options Options for collection.
* @returns A desired result, or `undefined` if the collector expired.
*/
static collectByButton<T>(message: Message, retriever: ButtonRetriever<T>, options?: CollectOptions): Promise<{
intr: ButtonInteraction;
value: T;
} | undefined>;
/**
* Collect a response by select menu.
* @param message Message to collect select menu interactions on.
* @param retriever Method which takes a collected select menu interaction and returns a desired result, or `undefined` if invalid.
* @param options Options for collection.
* @returns A desired result, or `undefined` if the collector expired.
*/
static collectBySelectMenu<T>(message: Message, retriever: SelectMenuRetriever<T>, options?: CollectOptions): Promise<{
intr: SelectMenuInteraction;
value: T;
} | undefined>;
/**
* Collect a response through a modal.
* @param message Message to collect button interactions on.
* @param modal Modal to show when the button is clicked.
* @param retriever Method which takes a collected modal interaction and returns a desired result, or `undefined` if invalid.
* @param options Options for collection.
* @returns A desired result, or `undefined` if the collector expired.
*/
static collectByModal<T>(message: Message, modal: ModalBuilder, retriever: ModalRetriever<T>, options?: CollectOptions): Promise<{
intr: ModalSubmitInteraction;
value: T;
} | undefined>;
/**
* Collect a response by reactions.
* @param message Message to collect reactions on.
* @param retriever Method which takes a collected reaction and returns a desired result, or `undefined` if invalid.
* @param options Options for collection.
* @returns A desired result, or `undefined` if the collector expired.
*/
static collectByReaction<T>(message: Message, retriever: ReactionRetriever<T>, options?: CollectOptions): Promise<T | undefined>;
/**
* Collect a response by messages.
* @param channel Channel to collect messages on.
* @param retriever Method which takes a collected message and returns a desired result, or `undefined` if invalid.
* @param options Options for collection.
* @returns A desired result, or `undefined` if the collector expired.
*/
static collectByMessage<T>(channel: TextBasedChannel, retriever: MessageRetriever<T>, options?: CollectOptions): Promise<T | undefined>;
}
export interface CollectOptions {
/**
* Time in milliseconds before the collector expires.
* @defaultValue `120000` (2 minutes)
*/
time?: number;
/**
* Whether the collector time should be reset on a invalid response.
* @defaultValue `true`
*/
reset?: boolean;
/**
* Target user to collect from.
*/
target?: User;
/**
* Method which takes message and returns a boolean as to whether the collector should be silently stopped.
*/
stopFilter?: StopFilter;
/**
* Method which is run if the timer expires.
*/
onExpire?: ExpireFunction;
}
export type StopFilter = (message: Message) => boolean;
export type ExpireFunction = () => void | Promise<void>;
export type ButtonRetriever<T> = (buttonInteraction: ButtonInteraction) => Promise<{
intr: ButtonInteraction;
value: T;
} | undefined>;
export type SelectMenuRetriever<T> = (selectMenuInteraction: SelectMenuInteraction) => Promise<{
intr: SelectMenuInteraction;
value: T;
} | undefined>;
export type ModalRetriever<T> = (modalSubmitInteraction: ModalSubmitInteraction) => Promise<{
intr: ModalSubmitInteraction;
value: T;
} | undefined>;
export type ReactionRetriever<T> = (messageReaction: MessageReaction, reactor: User) => Promise<T | undefined>;
export type MessageRetriever<T> = (message: Message) => Promise<T | undefined>;