a-djs-handler
Version:
Simple command handler for discord.js v13.
1,022 lines (1,003 loc) • 43.4 kB
TypeScript
import * as discord_js from 'discord.js';
import { ClientEvents, Collection, Message, Interaction, EmbedBuilder, User, TextBasedChannel, ButtonInteraction, SelectMenuInteraction, ApplicationCommandType, ChatInputCommandInteraction, PermissionsString, ApplicationCommandOptionData, Client, Snowflake, GuildMember, GuildChannel, ThreadChannel, Role, Emoji, Guild, BufferResolvable, AttachmentBuilder, ClientOptions, Channel, TextChannel, CategoryChannel, VoiceChannel, ContextMenuCommandInteraction, AutocompleteInteraction, ActionRowBuilder, ButtonBuilder, SelectMenuBuilder, NewsChannel, DMChannel, RoleResolvable, ChannelType, StageChannel, ButtonStyle, InteractionResponse, PermissionResolvable, MappedChannelCategoryTypes as MappedChannelCategoryTypes$1 } from 'discord.js';
import { APIMessage, APIButtonComponent, APISelectMenuComponent } from 'discord-api-types/v9';
import { Stream } from 'stream';
import { EventEmitter } from 'events';
/**
* The base event to define events.
* @public
*/
declare abstract class Event {
/**
* @param name The name of the event.
*/
name: string;
/**
* @param name The name of the event.
*/
constructor(name: keyof ClientEvents);
/**
* The function to excuse for the event.
* @param handler The handler.
* @param args The arguments for the event.
*/
abstract run(handler: Handler, ...args: any): Promise<any>;
}
/**
* The handler.
* @public
*/
declare class Handler {
/**
* The Discord.JS client.
*/
client: MoodyClient;
/**
* The handler options.
*/
options: Req<HandlerOptions, 'owners' | 'eventsPath'>;
private commandsToDeploy;
/**
* The client util.
*/
util: ClientUtil;
cooldowns: Collection<string, Collection<string, number>>;
/**
* @param client The Discord.JS client.
* @param options The options for the handler.
*/
constructor(options: HandlerOptions);
/**
* A function to start listening for prompts.
* @param message The message to listen for prompts.
*/
listenForPrompts(message: Message): Promise<boolean>;
/**
* A function to register commands.
* @param dir The directory to register commands from.
* @internal
* @private
*/
private registerCommands;
/**
* A function to register events.
* @param dir The directory to register events from.
* @internal
* @private
*/
private registerEvents;
/**
* A function to register the default events.
* @param events The events to register.
* @public
*/
private deployCommands;
/**
* The function to start the client.
* @public
*/
start(): Promise<void>;
handleInteraction(interaction: Interaction): Promise<discord_js.InteractionResponse<boolean> | undefined>;
handleMessage(message: Message): Promise<boolean | Message<true> | Message<false> | undefined>;
/**
* A function to start a prompt.
* @param message The message for the prompt.
* @param msg The content or EmbedBuilder of the message.
* @param options The options for the prompt.
* @param user The user to send the prompt to.
*/
prompt(message: null, msg: string | EmbedBuilder | EmbedBuilder[], options: PromptOptions, user: User): Promise<Message>;
prompt(message: Message, msg: string | EmbedBuilder | EmbedBuilder[], options: PromptOptions, user?: User | null): Promise<Message>;
prompt(message: Message | null, msg: string | EmbedBuilder | EmbedBuilder[], options: PromptOptions & {
multiple: true;
}, user?: User | null): Promise<Collection<string, Message>>;
}
/**
* @typedef {object} PromptOptions
* Note: Setting the `time` option to `Infinity` is strongly not advised, as it can cause confusion for the user, and may also cause the promise to
* never be garbage collected if the prompt is never fulfilled.
* @property {number} time The amount of milliseconds to wait before ending the prompt from time. Set this to `0` or `Infinity` for no time limit.
* @property {?boolean} cancellable Whether or not the user should be able to reply with cancel to cancel the ongoing prompt.
* @property {Array<any>|number|Function|RegExp} filter Called with the message and `Prompt` instance to determine whether a
* message should be deleted or not. Should not include filtering the user (done internally).
* @property {string|Function} correct Called with the message and `Prompt` instance that should handle when
* a message does not pass the filter.
* @property {?number} messages The amount of messages to accept before resolving the promise.
* @property {?number} attempts The amount of times the user is able to fail the filter before having the prompt cancelled. You can set this to `0` or
* `Infinity` for infinite attempts permitted.
* @property {?boolean} autoRespond Whether or not the bot should automatically respond when the prompt is cancelled/out of time with
* `Cancelled prompt.`, or when the max attempts are exceeded, `Too many attempts..` If disabled, you should probably handle this on the promise's
* rejection.
* @property {?boolean} invisible Whether or not the prompt is permitted to coexist with another prompt in the same channel.
* @property {?Function} matchUntil Continues matching until the function provided returns true
* or when the amount of messages matched is equal to options.messages.
*/
/**
* An instance of this is created whenever `Call#prompt` is called successfully and then added to `handler#prompts` and removed once the prompt is
* finished. All parameters translate directly into properties.
*/
declare class PromptError extends Error {
}
/**
* The prompt class for prompts.
* @public
*/
declare class Prompt {
/**
* The max attempts for the prompt.
*/
attempts: number;
ended: boolean;
values: Collection<string, Message>;
startedAt: number;
user: User;
channel: TextBasedChannel;
options: PromptOptions & {
multiple: boolean;
};
resolve: Function;
reject: Function;
client: MoodyClient;
interaction: boolean;
/**
* The options for the prompt.
* @param user The user the prompt is based around.
* @param channel The channel the prompt is in.
* @param options The options of the prompt.
* @param resolve The function to resolve the promise.
* @param reject The function to reject the promise.
* @param ended Whether or not the prompt has been ended.
* @param attempts The amount of attempts the user has made to complete the prompt.
* @param values The `Message` objects collected by the prompt.
*/
constructor(client: MoodyClient, user: User, channel: TextBasedChannel, options: PromptOptions & {
multiple: boolean;
}, resolve: Function, reject: Function);
/**
* Adds a message object to the values if it passes the filter provided, otherwise calling the correct function provided.
* @param message
*/
addInput(message: Message): Promise<any>;
/**
* Ends the prompt for whatever reason, rejecting the promise if an unsuccessful completion.
* @param reason
*/
end(reason: string, interaction?: ButtonInteraction | SelectMenuInteraction): any;
}
declare class InteractionContext<T extends ApplicationCommandType | 'Autocomplete' = ApplicationCommandType> {
readonly interaction: InteractionTypeReducer<T, ChatInputCommandInteraction>;
readonly client: MoodyClient;
command: InteractionCommand<T extends 'Autocomplete' ? ApplicationCommandType.ChatInput : T>;
constructor(options: InteractionContextOptions<T>);
get guild(): discord_js.Guild | null;
get channel(): discord_js.TextBasedChannel | null;
get member(): discord_js.GuildMember | null;
get user(): discord_js.User;
get roles(): discord_js.GuildMemberRoleManager | null;
get permissions(): Readonly<discord_js.PermissionsBitField> | null;
get handler(): Handler;
inGuild(): this is InteractionContext<T>;
isCommand(): this is InteractionContext<ApplicationCommandType.ChatInput>;
isUserContextMenu(): this is InteractionContext<ApplicationCommandType.User>;
isMessageContextMenu(): this is InteractionContext<ApplicationCommandType.Message>;
isBotOwner(): boolean;
isGuildAdmin(): boolean;
isGuildOwner(): boolean;
getUser(text: string): Promise<discord_js.User | null>;
getMember(text: string): Promise<discord_js.GuildMember | null>;
getRole(text: string): Promise<discord_js.Role | null>;
prompt(msg: string | EmbedBuilder | EmbedBuilder[], options: PromptOptions): Promise<discord_js.Message<boolean>>;
hasRolesAny(roles: string[]): boolean;
hasRolesAll(roles: string[]): boolean;
}
declare abstract class InteractionCommand<T extends ApplicationCommandType = ApplicationCommandType.ChatInput> {
name: string;
description: string;
ownerOnly: boolean;
userPermissions: PermissionsString[];
botPermissions: PermissionsString[];
userRoles: string[];
channel: 'guild' | 'dm' | 'both';
guildId?: string;
type: T;
options: ApplicationCommandOptionData[];
category: string;
autocomplete: boolean;
cooldown: number;
constructor(options: InteractionCommandOptions<T>);
abstract run(context: InteractionContext<T>): Promise<any> | any;
runAutocomplete?(context: InteractionContext<'Autocomplete'>): Promise<any> | any;
toJSON(): any;
}
/**
* The Client class.
* @public
*/
declare class MoodyClient extends Client {
/**
* A collection of collected messages.
*/
prompts: Collection<string, Prompt>;
interactions: Collection<string, InteractionCommand>;
/**
* A collection of the commands.
*/
commands: Collection<string, Command>;
/**
* A collection of the events.
*/
events: Collection<string, Event>;
/**
* A collection of the aliases for the commands.
*/
aliases: Collection<string, Command>;
/**
* The handler class.
*/
handler: Handler;
}
declare class ClientUtil {
client: MoodyClient;
constructor(client: MoodyClient);
/**
* Resolves a user from a string, such as an ID, a name, or a mention.
* @param text - Text to resolve.
* @param users - Collection of users to find in.
* @param [caseSensitive=false] - Makes finding by name case sensitive.
* @param [wholeWord=false] - Makes finding by name match full word only.
* @returns {User}
*/
resolveUser(text: string, users: Collection<Snowflake, User>, caseSensitive?: boolean, wholeWord?: boolean): User | undefined;
/**
* Resolves multiple users from a string, such as an ID, a name, or a mention.
* @param text - Text to resolve.
* @param users - Collection of users to find in.
* @param [caseSensitive=false] - Makes finding by name case sensitive.
* @param [wholeWord=false] - Makes finding by name match full word only.
* @returns {Collection<Snowflake, User>}
*/
resolveUsers(text: string, users: Collection<Snowflake, User>, caseSensitive?: boolean, wholeWord?: boolean): Collection<Snowflake, User>;
/**
* Checks if a string could be referring to a user.
* @param text - Text to check.
* @param user - User to check.
* @param [caseSensitive=false] - Makes checking by name case sensitive.
* @param [wholeWord=false] - Makes checking by name match full word only.
* @returns {boolean}
*/
checkUser(text: string, user: User, caseSensitive?: boolean, wholeWord?: boolean): boolean;
/**
* Resolves a member from a string, such as an ID, a name, or a mention.
* @param text - Text to resolve.
* @param members - Collection of members to find in.
* @param [caseSensitive=false] - Makes finding by name case sensitive.
* @param [wholeWord=false] - Makes finding by name match full word only.
* @returns {GuildMember}
*/
resolveMember(text: string, members: Collection<Snowflake, GuildMember>, caseSensitive?: boolean, wholeWord?: boolean): GuildMember | undefined;
/**
* Resolves multiple members from a string, such as an ID, a name, or a mention.
* @param text - Text to resolve.
* @param members - Collection of members to find in.
* @param [caseSensitive=false] - Makes finding by name case sensitive.
* @param [wholeWord=false] - Makes finding by name match full word only.
* @returns {Collection<Snowflake, GuildMember>}
*/
resolveMembers(text: string, members: Collection<Snowflake, GuildMember>, caseSensitive?: boolean, wholeWord?: boolean): Collection<Snowflake, GuildMember>;
/**
* Checks if a string could be referring to a member.
* @param text - Text to check.
* @param member - Member to check.
* @param [caseSensitive=false] - Makes checking by name case sensitive.
* @param [wholeWord=false] - Makes checking by name match full word only.
* @returns {boolean}
*/
checkMember(text: string, member: GuildMember, caseSensitive?: boolean, wholeWord?: boolean): boolean;
/**
* Resolves a channel from a string, such as an ID, a name, or a mention.
* @param text - Text to resolve.
* @param channels - Collection of channels to find in.
* @param [caseSensitive=false] - Makes finding by name case sensitive.
* @param [wholeWord=false] - Makes finding by name match full word only.
* @returns {Channel}
*/
resolveChannel(text: string, channels: Collection<Snowflake, GuildChannel | ThreadChannel>, caseSensitive?: boolean, wholeWord?: boolean): GuildChannel | ThreadChannel | undefined;
/**
* Resolves multiple channels from a string, such as an ID, a name, or a mention.
* @param text - Text to resolve.
* @param channels - Collection of channels to find in.
* @param [caseSensitive=false] - Makes finding by name case sensitive.
* @param [wholeWord=false] - Makes finding by name match full word only.
* @returns {Collection<Snowflake, Channel>}
*/
resolveChannels(text: string, channels: Collection<Snowflake, GuildChannel | ThreadChannel>, caseSensitive?: boolean, wholeWord?: boolean): Collection<Snowflake, GuildChannel | ThreadChannel>;
/**
* Checks if a string could be referring to a channel.
* @param text - Text to check.
* @param channel - Channel to check.
* @param [caseSensitive=false] - Makes checking by name case sensitive.
* @param [wholeWord=false] - Makes checking by name match full word only.
* @returns {boolean}
*/
checkChannel(text: string, channel: GuildChannel | ThreadChannel, caseSensitive?: boolean, wholeWord?: boolean): boolean;
/**
* Resolves a role from a string, such as an ID, a name, or a mention.
* @param text - Text to resolve.
* @param roles - Collection of roles to find in.
* @param [caseSensitive=false] - Makes finding by name case sensitive.
* @param [wholeWord=false] - Makes finding by name match full word only.
* @returns {Role}
*/
resolveRole(text: string, roles: Collection<Snowflake, Role>, caseSensitive?: boolean, wholeWord?: boolean): Role | undefined;
/**
* Resolves multiple roles from a string, such as an ID, a name, or a mention.
* @param text - Text to resolve.
* @param roles - Collection of roles to find in.
* @param [caseSensitive=false] - Makes finding by name case sensitive.
* @param [wholeWord=false] - Makes finding by name match full word only.
* @returns {Collection<Snowflake, Role>}
*/
resolveRoles(text: string, roles: Collection<Snowflake, Role>, caseSensitive?: boolean, wholeWord?: boolean): Collection<Snowflake, Role>;
/**
* Checks if a string could be referring to a role.
* @param text - Text to check.
* @param role - Role to check.
* @param [caseSensitive=false] - Makes checking by name case sensitive.
* @param [wholeWord=false] - Makes checking by name match full word only.
* @returns {boolean}
*/
checkRole(text: string, role: Role, caseSensitive?: boolean, wholeWord?: boolean): boolean;
/**
* Resolves a custom emoji from a string, such as a name or a mention.
* @param text - Text to resolve.
* @param emojis - Collection of emojis to find in.
* @param [caseSensitive=false] - Makes finding by name case sensitive.
* @param [wholeWord=false] - Makes finding by name match full word only.
* @returns {Emoji}
*/
resolveEmoji(text: string, emojis: Collection<Snowflake, Emoji>, caseSensitive?: boolean, wholeWord?: boolean): Emoji | undefined;
/**
* Resolves multiple custom emojis from a string, such as a name or a mention.
* @param text - Text to resolve.
* @param emojis - Collection of emojis to find in.
* @param [caseSensitive=false] - Makes finding by name case sensitive.
* @param [wholeWord=false] - Makes finding by name match full word only.
* @returns {Collection<Snowflake, Emoji>}
*/
resolveEmojis(text: string, emojis: Collection<Snowflake, Emoji>, caseSensitive?: boolean, wholeWord?: boolean): Collection<Snowflake, Emoji>;
/**
* Checks if a string could be referring to a emoji.
* @param text - Text to check.
* @param emoji - Emoji to check.
* @param [caseSensitive=false] - Makes checking by name case sensitive.
* @param [wholeWord=false] - Makes checking by name match full word only.
* @returns {boolean}
*/
checkEmoji(text: string, emoji: Emoji, caseSensitive?: boolean, wholeWord?: boolean): boolean;
/**
* Resolves a guild from a string, such as an ID or a name.
* @param text - Text to resolve.
* @param guilds - Collection of guilds to find in.
* @param [caseSensitive=false] - Makes finding by name case sensitive.
* @param [wholeWord=false] - Makes finding by name match full word only.
* @returns {Guild}
*/
resolveGuild(text: string, guilds: Collection<Snowflake, Guild>, caseSensitive?: boolean, wholeWord?: boolean): Guild | undefined;
/**
* Resolves multiple guilds from a string, such as an ID or a name.
* @param text - Text to resolve.
* @param guilds - Collection of guilds to find in.
* @param [caseSensitive=false] - Makes finding by name case sensitive.
* @param [wholeWord=false] - Makes finding by name match full word only.
* @returns {Collection<Snowflake, Guild>}
*/
resolveGuilds(text: string, guilds: Collection<Snowflake, Guild>, caseSensitive?: boolean, wholeWord?: boolean): Collection<Snowflake, Guild>;
/**
* Checks if a string could be referring to a guild.
* @param text - Text to check.
* @param guild - Guild to check.
* @param [caseSensitive=false] - Makes checking by name case sensitive.
* @param [wholeWord=false] - Makes checking by name match full word only.
* @returns {boolean}
*/
checkGuild(text: string, guild: Guild, caseSensitive?: boolean, wholeWord?: boolean): boolean;
/**
* Array of permission names.
* @returns {string[]}
*/
static permissionNames(): string[];
/**
* Resolves a permission number and returns an array of permission names.
* @param number - The permissions number.
* @returns {string[]}
*/
static resolvePermissionNumber(number: bigint): string[];
/**
* Compares two member objects presences and checks if they stopped or started a stream or not.
* Returns `0`, `1`, or `2` for no change, stopped, or started.
* @param oldMember - The old member.
* @param newMember - The new member.
* @returns {number}
*/
static compareStreaming(oldMember: GuildMember, newMember: GuildMember): number;
/**
* Combination of `<Client>.fetchUser()` and `<Guild>.fetchMember()`.
* @param guild Guild to fetch in.
* @param id ID of the user.
* @param cache - Whether or not to add to cache.
* @returns {Promise<GuildMember>}
*/
fetchMember(guild: Guild, id: string, cache: boolean): Promise<GuildMember>;
/**
* Makes a MessageAttachment.
* @param file - The file.
* @param [name] - The filename.
* @returns {MessageAttachment}
*/
static attachment(file: BufferResolvable | Stream, name: string): AttachmentBuilder;
/**
* Converts Milliseconds into days, hours, minutes and seconds.
* @param ms Milliseconds to convert.
* @returns {string}
*/
static duration(ms: number | null): string | undefined;
/**
* Converts a date into a formatted string.
* @param date The date to convert.
* @returns Formatted text.
*/
static checkDays(date: Date): string;
static checkFlags(str: string, flag: string, type?: string): string | null;
/**
* Moves an element from the array to another index
* @param arr Array to move element in
* @param oldIndex Element's index to move from
* @param newIndex New element's index to move to
*/
static arrayMove<T>(array: T[], initialIndex: number, finalIndex: number): T[];
/**
* Checks to see if the author is above the target in role hierarchy
* @param author Member to check from
* @param target Member to check for
*/
static roleHierarchy(author: GuildMember, target: GuildMember): boolean | undefined;
/**
* Capitalizes the first letter of text.
* @param text Text to capitalize.
* @returns Capitalized text.
*/
static capitalize(text: string): string;
}
declare type DefaultEvents = 'message' | 'ready' | 'interactionCreate';
interface HandlerOptions extends ClientOptions {
prefix: string;
token: string;
commandsPath: string;
deployCommands?: boolean;
listenForPrompts?: boolean;
eventsPath?: string;
owners?: string[];
defaultEvents?: false | DefaultEvents[];
}
declare type Req<T, K extends keyof T> = Omit<T, K> & Required<Pick<T, K>>;
declare enum ArgumentTypes {
STRING = "string",
UPPERCASE = "uppercase",
LOWERCASE = "lowercase",
CHARCODES = "charCodes",
BOOLEAN = "boolean",
INTEGER = "number",
FLOAT = "number",
COLOR = "color",
CHANNEL = "channel",
CHANNELS = "channels",
TEXT_CHANNEL = "textChannel",
VOICE_CHANNEL = "voiceChannel",
CATEGORY = "category",
MESSAGE = "message",
MESSAGES = "messages",
USER = "user",
USERS = "users",
MEMBER = "member",
MEMBERS = "members",
ROLE = "role",
ROLES = "roles",
URL = "url",
DATE = "date",
COMMAND = "command",
TEXT = "text"
}
declare type ArgumentType = keyof typeof ArgumentTypes | ArgumentTypes;
declare const enum ArgumentFlags {
Remainder = 1,
Optional = 2
}
declare type Arg = string | string[] | number | number[] | boolean | boolean[] | Date | Command | Channel | TextChannel | CategoryChannel | VoiceChannel | Message | User | Role | GuildMember | Collection<string, Channel> | Collection<string, Role> | Collection<string, User> | Collection<string, GuildMember> | null;
/**
* The argument object for the command.
* @template T The type for the choices.
*/
interface Argument<T extends ArgumentType = ArgumentType> {
name: string;
key: string;
type: T;
flags?: number;
choices?: string[];
prompt?: boolean;
default?: (message: Message) => Arg;
}
declare type Arguments<T extends ArgumentType = ArgumentType> = Argument<T>[];
declare type CommandArgs = Record<string, Arg>;
declare type InteractionCommandTypes = ChatInputCommandInteraction | ContextMenuCommandInteraction | AutocompleteInteraction;
declare const enum InteractionTypes {
COMMAND = 0
}
interface ContextOptions {
message: Message;
args: string[];
command: Command;
client: MoodyClient;
}
declare type ComponentsResolvable = ActionRowBuilder<ComponentResolvable>[] | Message | APIMessage;
declare type ComponentResolvable = ButtonBuilder | SelectMenuBuilder;
interface InteractionContextOptions<T extends ApplicationCommandType | 'Autocomplete'> {
interaction: InteractionTypeReducer<T, ChatInputCommandInteraction>;
command: InteractionCommand<T extends 'Autocomplete' ? ApplicationCommandType.ChatInput : T>;
client: MoodyClient;
}
interface PromptOptions {
time: number;
filter: ((message: Message, prompt: Prompt) => boolean | Promise<boolean>) | string | string[] | number | RegExp;
correct: string | ((message: Message, prompt: Prompt) => Promise<any> | any);
cancellable?: boolean;
channel?: TextChannel | NewsChannel | DMChannel;
formatTrigger?: (prompt: Prompt, ...msg: (EmbedBuilder | string)[]) => Array<any>;
formatCorrect?: (prompt: Prompt, msg: string | EmbedBuilder[]) => {
content: string;
} | {
embeds: EmbedBuilder[];
};
rawFilter?: ((message: Message, prompt: Prompt) => Promise<boolean> | boolean) | string | string[] | number | RegExp;
messages?: number;
attempts?: number;
autoRespond?: boolean;
invisible?: boolean;
addLastMatch?: boolean;
matchUntil?: (message: Message, prompt: Prompt) => boolean;
}
declare type PromptType = 'text' | 'select' | 'button';
declare type PromptTypeReducer<State extends PromptType, CachedType, RawType = CachedType, PresentType = CachedType | RawType, Fallback = PresentType | null> = [State] extends ['button'] ? ButtonInteraction | Message : [State] extends ['select'] ? SelectMenuInteraction | Message : [State] extends ['text'] ? Message : [State] extends ['text' | 'select' | 'button'] ? PresentType : Fallback;
/**
* @typedef {object} CommandOptions
* @property {string} name Name of the command.
* @property {string} category Category of the command.
* @property {?Array<string>} aliases Aliases for the command.
* @property {?string} usage Usage for the command.
* @property {?number} cooldown Command cooldown in seconds.
* @property {?boolean} ownerOnly If the command is restricted to the bot owner.
* @property {?Array<PermissionsString>} userPermissions Permissions for the user.
* @property {?Array<PermissionsString>} botPermissions Permissions for the bot.
* @property {?Array<string>} examples Examples for the command.
* @property {?Array<string|RoleResolvable|Role>} userRoles Roles that are able to run the command.
* @property {?boolean} guildOnly If the command is restricted to guilds.
*/
interface CommandOptions {
name: string;
category: string;
description: string;
aliases?: string[];
usage?: string;
cooldown?: number;
ownerOnly?: boolean;
userPermissions?: PermissionsString[];
botPermissions?: PermissionsString[];
examples?: string[];
userRoles?: (string | RoleResolvable | Role)[];
channel?: 'guild' | 'dm' | 'both';
args?: Arguments;
}
interface InteractionCommandOptions<T extends ApplicationCommandType> {
name: string;
description: string;
type: T;
options?: T extends ApplicationCommandType.User ? never : T extends ApplicationCommandType.Message ? never : ApplicationCommandOptionData[];
ownerOnly?: boolean;
category: string;
userPermissions?: PermissionsString[];
botPermissions?: PermissionsString[];
userRoles?: string[];
channel?: 'guild' | 'dm' | 'both';
guildId?: string;
cooldown?: number;
}
declare type InteractionTypeReducer<State extends ApplicationCommandType | 'Autocomplete', CachedType, RawType = CachedType, PresentType = CachedType | RawType, Fallback = PresentType> = [State] extends [ApplicationCommandType.ChatInput] ? ChatInputCommandInteraction : [State] extends [ApplicationCommandType.User] ? ContextMenuCommandInteraction : [State] extends [ApplicationCommandType.Message] ? ContextMenuCommandInteraction : [State] extends ['Autocomplete'] ? AutocompleteInteraction : [State] extends [ApplicationCommandType.ChatInput | ApplicationCommandType.User | ApplicationCommandType.Message] ? PresentType : Fallback;
declare type KeyedEnum<K, T> = {
[Key in keyof K]: T | string;
};
declare type EnumValueMapped<E extends KeyedEnum<T, number>, T extends Partial<Record<keyof E, unknown>>> = T & {
[Key in keyof T as E[Key]]: T[Key];
};
declare type MappedChannelCategoryTypes = EnumValueMapped<typeof ChannelType & {
Any: number;
}, {
GuildNews: NewsChannel;
GuildVoice: VoiceChannel;
GuildText: TextChannel;
GuildStageVoice: StageChannel;
Any: GuildChannel;
}>;
declare type ExcludeEnum<T, K extends keyof T> = Exclude<keyof T | T[keyof T], K | T[K]>;
declare type CategoryChannelTypes = ExcludeEnum<typeof ChannelType, 'DM' | 'GroupDM' | 'GuildPublicThread' | 'GuildNewsThread' | 'GuildPrivateThread' | 'GuildCategory'>;
declare type MappedChannelCategoryType = MappedChannelCategoryTypes;
declare type MappedGuildChannelTypes = EnumValueMapped<typeof ChannelType, {
GuildCategory: CategoryChannel;
}> & MappedChannelCategoryTypes;
declare type GuildChannelTypes = CategoryChannelTypes | ChannelType.GuildCategory | 'Any';
declare function disableComponent(component: APIButtonComponent | APISelectMenuComponent | ButtonBuilder | SelectMenuBuilder): void;
declare function disableComponents(components: ComponentsResolvable, customIds?: string[]): ActionRowBuilder[];
declare function paginateComponents(components: ComponentResolvable[]): ActionRowBuilder[];
declare const userIDRegex: RegExp;
declare const auditLogRegex: RegExp;
declare const urlRegex: RegExp;
declare const validTimeRegex: RegExp;
declare const videoFileRegex: RegExp;
declare const hexColorRegex: RegExp;
declare const defaultEmojiRegex: RegExp;
declare const emojiIDArgRegex: RegExp;
declare const emojiIDRegex: RegExp;
declare const inviteRegex: RegExp;
declare const discordOnlyInviteRegex: RegExp;
declare const fullInviteRegex: RegExp;
declare const defaultAvatar = "https://cdn.discordapp.com/embed/avatars/0.png";
declare const imageFileTypes: string[];
declare const badWords: string[];
declare const Permissions: {
ADD_REACTIONS: string;
ADMINISTRATOR: string;
ATTACH_FILES: string;
BAN_MEMBERS: string;
CHANGE_NICKNAME: string;
CONNECT: string;
CREATE_INSTANT_INVITE: string;
DEAFEN_MEMBERS: string;
EMBED_LINKS: string;
KICK_MEMBERS: string;
MANAGE_CHANNELS: string;
MANAGE_EMOJIS: string;
MANAGE_GUILD: string;
MANAGE_MESSAGES: string;
MANAGE_NICKNAMES: string;
MANAGE_ROLES: string;
MANAGE_WEBHOOKS: string;
MENTION_EVERYONE: string;
MOVE_MEMBERS: string;
MUTE_MEMBERS: string;
PRIORITY_SPEAKER: string;
READ_MESSAGE_HISTORY: string;
SEND_MESSAGES: string;
SEND_TTS_MESSAGES: string;
SPEAK: string;
STREAM: string;
USE_EXTERNAL_EMOJIS: string;
USE_VAD: string;
VIEW_AUDIT_LOG: string;
VIEW_CHANNEL: string;
};
declare const MODERATION_LOG_TYPE: {
WARN: {
hex: number;
display: string;
};
PURGE: {
hex: number;
display: string;
};
TEMP_MUTE: {
hex: number;
display: string;
};
MUTE: {
hex: number;
display: string;
};
KICK: {
hex: number;
display: string;
};
TEMP_BAN: {
hex: number;
display: string;
};
BAN: {
hex: number;
display: string;
};
UNMUTE: {
hex: number;
display: string;
};
UNBAN: {
hex: number;
display: string;
};
REMOVE_INFRACTION: {
hex: number;
display: string;
};
};
declare const COLOR_TYPES: {
SUCCESS: number;
DANGER: number;
WARN: number;
INFO: number;
};
declare const colors: string[][];
declare const Constants_userIDRegex: typeof userIDRegex;
declare const Constants_auditLogRegex: typeof auditLogRegex;
declare const Constants_urlRegex: typeof urlRegex;
declare const Constants_validTimeRegex: typeof validTimeRegex;
declare const Constants_videoFileRegex: typeof videoFileRegex;
declare const Constants_hexColorRegex: typeof hexColorRegex;
declare const Constants_defaultEmojiRegex: typeof defaultEmojiRegex;
declare const Constants_emojiIDArgRegex: typeof emojiIDArgRegex;
declare const Constants_emojiIDRegex: typeof emojiIDRegex;
declare const Constants_inviteRegex: typeof inviteRegex;
declare const Constants_discordOnlyInviteRegex: typeof discordOnlyInviteRegex;
declare const Constants_fullInviteRegex: typeof fullInviteRegex;
declare const Constants_defaultAvatar: typeof defaultAvatar;
declare const Constants_imageFileTypes: typeof imageFileTypes;
declare const Constants_badWords: typeof badWords;
declare const Constants_Permissions: typeof Permissions;
declare const Constants_MODERATION_LOG_TYPE: typeof MODERATION_LOG_TYPE;
declare const Constants_COLOR_TYPES: typeof COLOR_TYPES;
declare const Constants_colors: typeof colors;
declare namespace Constants {
export {
Constants_userIDRegex as userIDRegex,
Constants_auditLogRegex as auditLogRegex,
Constants_urlRegex as urlRegex,
Constants_validTimeRegex as validTimeRegex,
Constants_videoFileRegex as videoFileRegex,
Constants_hexColorRegex as hexColorRegex,
Constants_defaultEmojiRegex as defaultEmojiRegex,
Constants_emojiIDArgRegex as emojiIDArgRegex,
Constants_emojiIDRegex as emojiIDRegex,
Constants_inviteRegex as inviteRegex,
Constants_discordOnlyInviteRegex as discordOnlyInviteRegex,
Constants_fullInviteRegex as fullInviteRegex,
Constants_defaultAvatar as defaultAvatar,
Constants_imageFileTypes as imageFileTypes,
Constants_badWords as badWords,
Constants_Permissions as Permissions,
Constants_MODERATION_LOG_TYPE as MODERATION_LOG_TYPE,
Constants_COLOR_TYPES as COLOR_TYPES,
Constants_colors as colors,
};
}
declare function uid(): string;
declare function customId(name: string, ...args: (string | number)[]): string;
interface MessageMenuConstructor {
client: MoodyClient;
channel: TextBasedChannel;
userId: string;
pages: MessagePages[];
ms: number;
}
declare type MessageButtonTypes = 'first' | 'last' | 'previous' | 'next' | 'delete' | 'stop';
interface MessageButtons {
style: Exclude<ButtonStyle, ButtonStyle.Link>;
customId: string;
value: MessageButtonTypes | ((msg: ButtonInteraction<'cached'>) => any);
}
interface MessagePages {
name: string;
content: EmbedBuilder;
buttons: Record<string, MessageButtons>;
}
declare class MessagePage {
name: string;
content: EmbedBuilder;
buttons: Record<string, MessageButtons>;
index: number;
constructor(name: string, content: EmbedBuilder, buttons: Record<string, MessageButtons>, index: number);
}
declare class MessagePaginateMenu extends EventEmitter {
client: MoodyClient;
channel: TextBasedChannel;
userId: string;
pages: MessagePage[];
ms: number;
private currentPage;
private pageIndex;
private menu;
private collector;
private interaction;
constructor({ client, channel, userId, pages, ms, }: MessageMenuConstructor);
start(): void;
stop(): void;
/**
* Delete the menu message.
*/
delete(): void;
/**
* Remove all reactions from the menu message.
*/
disableButtons(): void;
setPage(page?: number): void;
/**
* React to the new page with all of it's defined reactions
*/
addButtons(): void;
/**
* Start a reaction collector and switch pages where required.
*/
awaitButtons(): void;
}
interface MenuConstructor {
client: MoodyClient;
userId: string;
pages: Pages[];
ms: number;
}
declare type ButtonTypes = 'first' | 'last' | 'previous' | 'next' | 'delete' | 'stop';
interface Buttons {
style: Exclude<ButtonStyle, ButtonStyle.Link>;
customId: string;
value: ButtonTypes | ((msg: ButtonInteraction<'cached'>) => any);
}
interface Pages {
name: string;
content: EmbedBuilder;
buttons: Record<string, Buttons>;
}
declare class Page {
name: string;
content: EmbedBuilder;
buttons: Record<string, Buttons>;
index: number;
constructor(name: string, content: EmbedBuilder, buttons: Record<string, Buttons>, index: number);
}
declare class PaginateMenu extends EventEmitter {
client: MoodyClient;
userId: string;
pages: Page[];
ms: number;
private currentPage;
private pageIndex;
private msg?;
private collector;
private interactionResponse;
constructor({ client, userId, pages, ms, }: MenuConstructor);
start(interactionResponse: InteractionResponse): void;
stop(): void;
/**
* Delete the menu message.
*/
delete(): void;
generateRows(disabled?: boolean): ActionRowBuilder<ButtonBuilder>;
/**
* Remove all reactions from the menu message.
*/
disableButtons(): void;
setPage(interaction: ButtonInteraction | SelectMenuInteraction, page?: number): void;
/**
* React to the new page with all of it's defined reactions
*/
addButtons(interaction?: SelectMenuInteraction | ButtonInteraction): void;
/**
* Start a reaction collector and switch pages where required.
*/
awaitButtons(): void;
}
declare function generateCode(length: number): string;
/**
* The base command class used to define commands.
* @public
*/
declare abstract class Command {
/**
* @param name The name of the command.
*/
name: string;
/**
* @param category The category of the command.
*/
category: string;
/**
* @param description The description of the command.
*/
description: string;
/**
* @param aliases The aliases for the command.
*/
aliases: string[];
/**
* @param usage The command usage (how to use the command).
*/
usage: string;
/**
* @param cooldown The cooldown for the command in seconds.
*/
cooldown: number;
/**
* @param ownerOnly Whether the command is for the owner only.
*/
ownerOnly: boolean;
/**
* @param userPermissions The permissions of the user to use this command.
*/
userPermissions: PermissionsString[];
/**
* @param botPermissions The permissions of the bot to execute this command.
*/
botPermissions: PermissionsString[];
/**
* @param examples An array of examples of the command usage.
*/
examples: string[];
/**
* @param userRoles The required roles for the user to use this command.
*/
userRoles: RoleResolvable[];
/**
* @param guildOnly Whether the command can be used in DMs.
*/
channel: 'guild' | 'dm' | 'both';
/**
* @param options Options for the command.
*/
constructor(options: CommandOptions);
/**
* Checks if the user is a bot owner
* @param user User to check if they're a bot owner
*/
checkOwner(owners: string[], user: User): boolean;
/**
* Checks permission for the member in the guild.
* @param member Member of the guild
* @param perms Permissions to check for.
*/
checkPermission(member: GuildMember, perms: PermissionResolvable): boolean;
/**
* Function to parse args of a message.
* @param message The message to parse.
* @param args The raw args in the message.
* @param client The Client.
* @returns The parsed args.
*/
/**
* Run method for the command.
* @param client Discord.js client.
* @param message Message sent by the user.
* @param args Array of the message's content.
* @param util ClientUtil class.
*/
abstract run(context: Context): Promise<any> | any;
onBeforeRun(context: Context): Promise<boolean>;
onCancelRun(context: Context): Promise<boolean>;
}
declare class Context {
readonly message: Message;
readonly client: MoodyClient;
args: string[];
command: Command;
constructor(options: ContextOptions);
get guild(): discord_js.Guild | null;
get channel(): discord_js.DMChannel | discord_js.PartialDMChannel | discord_js.NewsChannel | discord_js.TextChannel | discord_js.PrivateThreadChannel | discord_js.PublicThreadChannel<boolean> | discord_js.VoiceChannel;
get member(): discord_js.GuildMember | null;
get user(): discord_js.User;
get roles(): discord_js.GuildMemberRoleManager | null;
get permissions(): Readonly<discord_js.PermissionsBitField> | null;
get handler(): Handler;
isBotOwner(): boolean;
isGuildAdmin(): boolean;
isGuildOwner(): boolean;
getUser(text: string): Promise<discord_js.User | null>;
getMember(text: string): Promise<discord_js.GuildMember | null>;
getRole(text: string): Promise<discord_js.Role | null>;
getChannel<T extends keyof MappedChannelCategoryTypes$1 = ChannelType.GuildText>(text: string, type?: T): Promise<MappedChannelCategoryTypes$1[T] | null>;
prompt(msg: string | EmbedBuilder | EmbedBuilder[], options: PromptOptions): Promise<Message<boolean>>;
hasRolesAny(roles: string[]): boolean | undefined;
hasRolesAll(roles: string[]): boolean | undefined;
}
export { Arg, Argument, ArgumentFlags, ArgumentType, ArgumentTypes, Arguments, ButtonTypes, Buttons, CategoryChannelTypes, ClientUtil, Command, CommandArgs, CommandOptions, ComponentResolvable, ComponentsResolvable, Constants, Context, ContextOptions, DefaultEvents, EnumValueMapped, Event, ExcludeEnum, GuildChannelTypes, Handler, HandlerOptions, InteractionCommand, InteractionCommandOptions, InteractionCommandTypes, InteractionContext, InteractionContextOptions, InteractionTypeReducer, InteractionTypes, KeyedEnum, MappedChannelCategoryType, MappedChannelCategoryTypes, MappedGuildChannelTypes, MenuConstructor, MessageButtonTypes, MessageButtons, MessageMenuConstructor, MessagePage, MessagePages, MessagePaginateMenu, MoodyClient, Page, Pages, PaginateMenu, Prompt, PromptError, PromptOptions, PromptType, PromptTypeReducer, Req, customId, disableComponent, disableComponents, generateCode, paginateComponents, uid };