@backs/bot-base
Version:
The 6th version of back's bot base.
658 lines (640 loc) • 32.8 kB
text/typescript
import * as discord_js from 'discord.js';
import { ColorResolvable, ClientOptions, Message, SlashCommandBuilder, SlashCommandOptionsOnlyBuilder, SlashCommandSubcommandsOnlyBuilder, ChatInputCommandInteraction, AutocompleteInteraction, ContextMenuCommandBuilder, UserContextMenuCommandInteraction, MessageContextMenuCommandInteraction, ButtonInteraction, ModalSubmitInteraction, ClientEvents, Interaction, Collection, ButtonBuilder as ButtonBuilder$1, ButtonComponentData, APIButtonComponent, ButtonStyle, ModalBuilder as ModalBuilder$1, ModalComponentData, APIModalInteractionResponseCallbackData, StringSelectMenuBuilder as StringSelectMenuBuilder$1, StringSelectMenuComponentData, APIStringSelectComponent, UserSelectMenuBuilder as UserSelectMenuBuilder$1, UserSelectMenuComponentData, APIUserSelectComponent, RoleSelectMenuBuilder as RoleSelectMenuBuilder$1, RoleSelectMenuComponentData, APIRoleSelectComponent, ChannelSelectMenuBuilder as ChannelSelectMenuBuilder$1, ChannelSelectMenuComponentData, APIChannelSelectComponent, MentionableSelectMenuBuilder as MentionableSelectMenuBuilder$1, MentionableSelectMenuComponentData, APIMentionableSelectComponent, EmbedBuilder, ActionRowBuilder, PermissionResolvable, LocaleString, StringSelectMenuInteraction, UserSelectMenuInteraction, ChannelSelectMenuInteraction, RoleSelectMenuInteraction, MentionableSelectMenuInteraction, GuildMember, APIInteractionGuildMember, Client } from 'discord.js';
import ConfigParser, { ConfigParserOptions } from '@backs/config-parser';
import { LoggerOptions, TypedLogger } from '@backs/logger';
type BotOptions<Configs extends Record<string, any>, Emojis extends Record<string, Emoji>, Colors extends Record<string, ColorResolvable>> = {
configOptions: Omit<ConfigParserOptions, "start">;
clientOptions: ConfigFunction<Configs, BotClientOptions>;
loggerOptions?: ConfigFunction<Configs, LoggerOptions<["error", "warn", "debug", "log", "info"]>>;
emojis?: ConfigFunction<Configs, Emojis>;
colors?: ConfigFunction<Configs, Colors>;
debug?: ConfigFunction<Configs, boolean>;
token?: ConfigFunction<Configs, string>;
events: ConfigFunction<Configs, string[]>;
commands: ConfigFunction<Configs, string[]>;
plugins?: ConfigFunction<Configs, string[]>;
enablePlugins?: ConfigFunction<Configs, boolean>;
owners?: ConfigFunction<Configs, string[]>;
};
type BotClientOptions = ClientOptions & {
browser?: "Discord iOS" | "Discord Android" | "Discord Web" | "Discord Windows" | "Discord macOS" | "Discord Linux" | string;
};
type ConfigFunction<C, T> = T | ((configs: C) => T);
type Emoji = `<:${string}:${number}>` | `<a:${string}:${number}>` | `:${string}:`;
type ExtractConfigFunctionType<C, T> = T extends ConfigFunction<C, infer U> ? U : never;
type PlainBotOptions<Configs extends Record<string, any>, Emojis extends Record<string, Emoji>, Colors extends Record<string, ColorResolvable>> = {
[K in keyof BotOptions<Configs, Emojis, Colors>]: ExtractConfigFunctionType<Configs, BotOptions<Configs, Emojis, Colors>[K]>;
};
declare class MessageCommand<T extends string> implements IMessageCommand<T> {
constructor(options: IMessageCommandOptions<T>);
commandType: "message";
data: MessageCommandOptions<T>;
run: (message: Message, args: MessageArguments<T>) => any | Promise<any>;
enabled?: boolean | undefined;
options?: AdvancedCommandOptions | undefined;
isIDBased(): this is IDBasedCommand<any>;
isSlashCommand(): this is ISlashCommand;
isContextMenuCommand(): this is IContextMenuCommand<"user" | "message">;
isMessageCommand(): this is IMessageCommand<T>;
}
declare class SlashCommand implements ISlashCommand {
constructor(options: ISlashCommandOptions);
commandType: "slash";
data: SlashCommandBuilder | SlashCommandOptionsOnlyBuilder | SlashCommandSubcommandsOnlyBuilder;
run: (interaction: ChatInputCommandInteraction) => any | Promise<any>;
autocomplete?: Record<string, (interaction: AutocompleteInteraction, value: string) => any | Promise<any>> | undefined;
enabled?: boolean | undefined;
options?: AdvancedCommandOptions | undefined;
isIDBased(): this is IDBasedCommand<any>;
isSlashCommand(): this is ISlashCommand;
isContextMenuCommand(): this is IContextMenuCommand<"user" | "message">;
isMessageCommand(): this is IMessageCommand<any>;
}
declare class ContextMenuCommand<T extends "user" | "message"> implements IContextMenuCommand<T> {
constructor(options: IContextMenuCommandOptions<T>);
commandType: T extends "user" ? "contextMenuUser" : "contextMenuMessage";
data: ContextMenuCommandBuilder;
type: T;
run: (interaction: T extends "user" ? UserContextMenuCommandInteraction : MessageContextMenuCommandInteraction) => any | Promise<any>;
enabled?: boolean | undefined;
options?: AdvancedCommandOptions | undefined;
isIDBased(): this is IDBasedCommand<any>;
isSlashCommand(): this is ISlashCommand;
isContextMenuCommand(): this is IContextMenuCommand<"user" | "message">;
isUserContextMenuCommand(): this is IContextMenuCommand<"user">;
isMessageContextMenuCommand(): this is IContextMenuCommand<"message">;
isMessageCommand(): this is IMessageCommand<any>;
}
declare class SelectMenuCommand<X extends keyof SelectMenus, T extends string[]> implements ISelectMenuCommand<X, T> {
constructor(options: ISelectMenuCommandOptions<X, T>);
commandType: "selectMenu";
run: (interaction: SelectMenus[X], args: Record<T[number], string | undefined>) => any | Promise<any>;
id: string;
type: X;
user?: boolean | undefined;
arguments?: T | undefined;
enabled?: boolean | undefined;
options?: AdvancedCommandOptions | undefined;
isIDBased(): this is IDBasedCommand<any>;
isSlashCommand(): this is ISlashCommand;
isContextMenuCommand(): this is IContextMenuCommand<"user" | "message">;
isMessageCommand(): this is IMessageCommand<any>;
isSelectMenuCommand(): this is ISelectMenuCommand<X, T>;
isButtonCommand(): this is IButtonCommand<T>;
isModalCommand(): this is IModalCommand<T>;
isStringSelectMenuCommand(): this is ISelectMenuCommand<"string", T>;
isUserSelectMenuCommand(): this is ISelectMenuCommand<"user", T>;
isChannelSelectMenuCommand(): this is ISelectMenuCommand<"channel", T>;
isRoleSelectMenuCommand(): this is ISelectMenuCommand<"role", T>;
isMentionableSelectMenuCommand(): this is ISelectMenuCommand<"mentionable", T>;
}
declare class ButtonCommand<T extends string[]> implements IButtonCommand<T> {
constructor(options: IButtonCommandOptions<T>);
commandType: "button";
run: (interaction: ButtonInteraction, args: Record<T[number], string | undefined>) => any | Promise<any>;
id: string;
user?: boolean | undefined;
arguments?: T | undefined;
enabled?: boolean | undefined;
options?: AdvancedCommandOptions | undefined;
isIDBased(): this is IDBasedCommand<any>;
isSlashCommand(): this is ISlashCommand;
isContextMenuCommand(): this is IContextMenuCommand<"user" | "message">;
isMessageCommand(): this is IMessageCommand<any>;
isSelectMenuCommand(): this is ISelectMenuCommand<any, T>;
isButtonCommand(): this is IButtonCommand<T>;
isModalCommand(): this is IModalCommand<T>;
}
declare class ModalCommand<T extends string[]> implements IModalCommand<T> {
constructor(options: IModalCommandOptions<T>);
commandType: "modal";
run: (interaction: ModalSubmitInteraction, args: Record<T[number], string | undefined>) => any | Promise<any>;
id: string;
user?: boolean | undefined;
arguments?: T | undefined;
enabled?: boolean | undefined;
options?: AdvancedCommandOptions | undefined;
isIDBased(): this is IDBasedCommand<any>;
isSlashCommand(): this is ISlashCommand;
isContextMenuCommand(): this is IContextMenuCommand<"user" | "message">;
isMessageCommand(): this is IMessageCommand<any>;
isSelectMenuCommand(): this is ISelectMenuCommand<any, T>;
isButtonCommand(): this is IButtonCommand<T>;
isModalCommand(): this is IModalCommand<T>;
}
interface IEvent<T extends keyof ClientEvents> {
name: T;
readableName?: string;
enabled?: boolean;
once?: boolean;
run: (...args: ClientEvents[T]) => any | Promise<any>;
}
declare class Event<T extends keyof ClientEvents> implements IEvent<T> {
constructor(options: IEvent<T>);
name: T;
readableName?: string;
enabled?: boolean;
once?: boolean;
run: (...args: ClientEvents[T]) => any | Promise<any>;
}
interface IPlugin {
name: string;
description: string;
enabled?: boolean;
version: `v${number}.${number}.${number}`;
events?: Partial<{
[name in keyof ClientEvents]: PluginEventOptions<name>;
}>;
commands?: PluginCommandOptions;
}
interface PluginEventOptions<name extends keyof ClientEvents> {
/**
* Runs before the emitted event executes.
* @returns `boolean` - If `false`, the function will return after executed.
*/
prerun?: (...args: ClientEvents[name]) => boolean | Promise<boolean>;
/**
* Runs after the emitted event executes.
* @returns `boolean` - If `false`, the function will return after executed.
*/
postrun?: (result: any, ...args: ClientEvents[name]) => boolean | Promise<boolean>;
}
interface PluginCommandOptions {
/**
* Runs before the command is identified.
* @returns `boolean` - If `false`, the function will return after executed.
*/
precommand?: (intOrMsg: Interaction<"cached"> | Message) => boolean | Promise<boolean>;
/**
* Runs after the command is identified & before the command is process *(ratelimit, permissions, etc.)*. Will not run if returned due to precommand or command not found.
* @returns `boolean` - If `false`, the function will return after executed.
*/
postcommand?: (intOrMsg: Interaction<"cached"> | Message, command: AnyCommand) => boolean | Promise<boolean>;
/**
* Runs after the command is processed and before it's executed. Will not run if returned to any previous conditions or in autocomplete command..
* @returns `boolean` - If `false`, the function will return after executed.
*/
postprocess?: (intOrMsg: Interaction<"cached"> | Message, command: AnyCommand) => boolean | Promise<boolean>;
/**
* Runs after the command is executed. Will not run if returned to any previous conditions.
* @returns `boolean` - If `false`, the function will return after executed.
*/
postrun?: (intOrMsg: Interaction<"cached"> | Message, command: AnyCommand, result: any) => boolean | Promise<boolean>;
}
interface IPluginManager {
store: Collection<string, Plugin>;
events: {
prerun: Partial<{
[name in keyof ClientEvents]: ((...args: ClientEvents[name]) => boolean | Promise<boolean>)[];
}>;
postrun: Partial<{
[name in keyof ClientEvents]: ((...args: ClientEvents[name]) => boolean | Promise<boolean>)[];
}>;
};
commands: {
precommand: ((intOrMsg: Interaction<"cached"> | Message) => boolean | Promise<boolean>)[];
postcommand: ((intOrMsg: Interaction<"cached"> | Message, command: AnyCommand) => boolean | Promise<boolean>)[];
postprocess: ((intOrMsg: Interaction<"cached"> | Message, command: AnyCommand) => boolean | Promise<boolean>)[];
postrun: ((intOrMsg: Interaction<"cached"> | Message, command: AnyCommand, result: any) => boolean | Promise<boolean>)[];
};
register(plugin: Plugin): void;
}
declare class Plugin implements IPlugin {
constructor(options: IPlugin);
name: string;
description: string;
enabled?: boolean;
version: `v${number}.${number}.${number}`;
events?: {
[name in keyof ClientEvents]: PluginEventOptions<name>;
};
commands?: PluginCommandOptions | undefined;
}
declare class ButtonBuilder extends ButtonBuilder$1 {
private customId;
private userId?;
private arguments;
constructor(data?: Partial<ButtonComponentData> | Partial<APIButtonComponent>);
setCustomId(id: string): this;
setUserId(id?: string): this;
setStyle(style: "blurple" | "gray" | "green" | "red" | "link" | ButtonStyle): this;
setArguments(...args: string[]): this;
}
declare class ModalBuilder extends ModalBuilder$1 {
private customId;
private userId?;
private arguments;
constructor(data?: Partial<ModalComponentData> | Partial<APIModalInteractionResponseCallbackData>);
setCustomId(id: string): this;
setUserId(id?: string): this;
setArguments(...args: string[]): this;
}
declare class StringSelectMenuBuilder extends StringSelectMenuBuilder$1 {
private customId;
private userId?;
private arguments;
constructor(data?: Partial<StringSelectMenuComponentData> | Partial<APIStringSelectComponent>);
setCustomId(id: string): this;
setUserId(id?: string): this;
setArguments(...args: string[]): this;
}
declare class UserSelectMenuBuilder extends UserSelectMenuBuilder$1 {
private customId;
private userId?;
private arguments;
constructor(data?: Partial<UserSelectMenuComponentData> | Partial<APIUserSelectComponent>);
setCustomId(id: string): this;
setUserId(id?: string): this;
setArguments(...args: string[]): this;
}
declare class RoleSelectMenuBuilder extends RoleSelectMenuBuilder$1 {
private customId;
private userId?;
private arguments;
constructor(data?: Partial<RoleSelectMenuComponentData> | Partial<APIRoleSelectComponent>);
setCustomId(id: string): this;
setUserId(id?: string): this;
setArguments(...args: string[]): this;
}
declare class ChannelSelectMenuBuilder extends ChannelSelectMenuBuilder$1 {
private customId;
private userId?;
private arguments;
constructor(data?: Partial<ChannelSelectMenuComponentData> | Partial<APIChannelSelectComponent>);
setCustomId(id: string): this;
setUserId(id?: string): this;
setArguments(...args: string[]): this;
}
declare class MentionableSelectMenuBuilder extends MentionableSelectMenuBuilder$1 {
private customId;
private userId?;
private arguments;
constructor(data?: Partial<MentionableSelectMenuComponentData> | Partial<APIMentionableSelectComponent>);
setCustomId(id: string): this;
setUserId(id?: string): this;
setArguments(...args: string[]): this;
}
interface IMultiPageEmbedData {
id?: string;
userId?: string;
expires?: number;
startingPage?: number;
embeds: EmbedBuilder[];
canLoop?: boolean;
jump?: boolean;
}
interface IMultiPageEmbed {
id?: string;
userId?: string;
expires: number;
startingPage: number;
embeds: EmbedBuilder[];
canLoop: boolean;
jump: boolean;
components: ActionRowBuilder<ButtonBuilder>[];
page: EmbedBuilder;
}
interface IMultiPageEmbedManager {
embeds: Collection<string, Omit<IMultiPageEmbedData, "id">>;
create(data: IMultiPageEmbedData, createBoolean: true, userId: string): MultiPageEmbed;
create(data: IMultiPageEmbedData, createBoolean: false): undefined;
create(data: IMultiPageEmbedData, createBoolean: boolean, userId?: string): MultiPageEmbed | undefined;
get(embedId: string, userId: string): MultiPageEmbed | undefined;
delete(id: string): void;
}
declare class MultiPageEmbed implements IMultiPageEmbed {
private _id;
private _userId?;
private _expires;
private _startingPage;
private _embeds;
private _canLoop;
private _jump;
get id(): string;
get userId(): string | undefined;
get expires(): number;
get startingPage(): number;
get embeds(): EmbedBuilder[];
get canLoop(): boolean;
get jump(): boolean;
constructor(data: IMultiPageEmbedData);
get components(): ActionRowBuilder<ButtonBuilder>[];
get page(): EmbedBuilder;
}
interface AdvancedCommandOptions {
runIn?: RunIn;
ratelimit?: Ratelimit;
restricted?: boolean;
users?: {
deny?: string[];
allow?: string[];
};
roles?: {
deny?: string[];
allow?: string[];
};
permissions?: PermissionsList;
help?: Help;
}
declare enum RunIn {
DM = 0,
Guild = 1,
Any = 2
}
interface PermissionsList {
allow?: PermissionResolvable[];
deny?: PermissionResolvable[];
allowMode?: PermissionsMode;
denyMode?: PermissionsMode;
}
declare enum PermissionsMode {
MatchNone = 0,
MatchOne = 1,
MatchAll = 2
}
interface Ratelimit {
user?: number;
guild?: number;
channel?: number;
global?: number;
}
interface Help {
name?: string;
description?: string;
usage: string;
category: string;
examples: string[];
}
interface BaseCommandOptions {
enabled?: boolean;
options?: AdvancedCommandOptions;
}
interface BaseCommand extends BaseCommandOptions {
commandType: "slash" | "contextMenuUser" | "contextMenuMessage" | "message" | "selectMenu" | "button" | "modal";
isIDBased: () => this is IDBasedCommand<any>;
isSlashCommand: () => this is ISlashCommand;
isContextMenuCommand: () => this is IContextMenuCommand<"user" | "message">;
isMessageCommand: () => this is IMessageCommand<any>;
}
type MessageArguments<S extends string> = S extends `<${infer Start}> ${infer Rest}` ? process<Start, true> & MessageArguments<Rest> : S extends `[${infer Start}] ${infer Rest}` ? process<Start, false> & MessageArguments<Rest> : S extends `<${infer Start}>` ? process<Start, true> : S extends `[${infer Start}]` ? process<Start, false> : never;
type process<arg extends string, required extends boolean> = arg extends `${infer name}:${infer options}` ? options extends `${infer _},${infer __}` ? required extends true ? {
[K in name]: CreateUnionFromCommaSeparated<options>;
} : {
[K in name]?: CreateUnionFromCommaSeparated<options>;
} : required extends true ? {
[K in name]: boolean;
} : {
[K in name]?: boolean;
} : required extends true ? {
[K in Remove<arg>]: string;
} : {
[K in Remove<arg>]?: string;
};
type Remove<S extends string> = RemoveRegex<RemoveEllipsis<S>>;
type RemoveRegex<T extends string> = T extends `${infer WithoutRegex}(${infer _})` ? WithoutRegex : T;
type RemoveEllipsis<T extends string> = T extends `${infer WithoutEllipsis}...` ? WithoutEllipsis : T;
type CreateUnionFromCommaSeparated<T extends string> = T extends `${infer First},${infer Rest}` ? First | CreateUnionFromCommaSeparated<Rest> : T;
interface MessageCommandOptions<T extends string> {
name: string;
readableName?: string;
description: string;
aliases?: string[];
arguments?: T;
nameLocalizations?: Partial<Record<LocaleString, string>>;
}
interface IMessageCommandOptions<T extends string> extends BaseCommandOptions {
data: MessageCommandOptions<T>;
run: (message: Message, args: MessageArguments<T>) => any | Promise<any>;
}
interface IMessageCommand<T extends string> extends BaseCommand {
commandType: "message";
data: MessageCommandOptions<T>;
run: (message: Message, args: MessageArguments<T>) => any | Promise<any>;
}
interface ISlashCommandOptions extends BaseCommandOptions {
data: SlashCommandBuilder | SlashCommandOptionsOnlyBuilder | SlashCommandSubcommandsOnlyBuilder;
run: (interaction: ChatInputCommandInteraction<"cached">) => any | Promise<any>;
autocomplete?: Record<string, (interaction: AutocompleteInteraction<"cached">, value: string) => any | Promise<any>>;
}
interface ISlashCommand extends BaseCommand {
commandType: "slash";
data: SlashCommandBuilder | SlashCommandOptionsOnlyBuilder | SlashCommandSubcommandsOnlyBuilder;
run: (interaction: ChatInputCommandInteraction<"cached">) => any | Promise<any>;
autocomplete?: Record<string, (interaction: AutocompleteInteraction<"cached">, value: string) => any | Promise<any>>;
}
interface IContextMenuCommandOptions<T extends "user" | "message"> extends BaseCommandOptions {
data: ContextMenuCommandBuilder;
type: T;
run: (interaction: T extends "user" ? UserContextMenuCommandInteraction<"cached"> : MessageContextMenuCommandInteraction<"cached">) => any | Promise<any>;
}
interface IContextMenuCommand<T extends "user" | "message"> extends BaseCommand {
commandType: T extends "user" ? "contextMenuUser" : "contextMenuMessage";
data: ContextMenuCommandBuilder;
type: T;
run: (interaction: T extends "user" ? UserContextMenuCommandInteraction<"cached"> : MessageContextMenuCommandInteraction<"cached">) => any | Promise<any>;
isUserContextMenuCommand: () => this is IContextMenuCommand<"user">;
isMessageContextMenuCommand: () => this is IContextMenuCommand<"message">;
}
interface SelectMenus {
string: StringSelectMenuInteraction<"cached">;
user: UserSelectMenuInteraction<"cached">;
channel: ChannelSelectMenuInteraction<"cached">;
role: RoleSelectMenuInteraction<"cached">;
mentionable: MentionableSelectMenuInteraction<"cached">;
}
interface IDBasedCommandOptions<T extends string[]> extends Omit<BaseCommandOptions, "options"> {
id: string;
/**
* If set to true, checks if the user is the same one in the user argument.
*/
user?: boolean;
arguments?: T;
}
interface IDBasedCommand<T extends string[]> extends Omit<BaseCommand, "options">, IDBasedCommandOptions<T> {
id: string;
/**
* If set to true, checks if the user is the same one in the user argument.
*/
user?: boolean;
arguments?: T;
isSelectMenuCommand: () => this is ISelectMenuCommand<any, T>;
isButtonCommand: () => this is IButtonCommand<T>;
isModalCommand: () => this is IModalCommand<T>;
}
interface ISelectMenuCommandOptions<X extends keyof SelectMenus, T extends string[]> extends IDBasedCommandOptions<T> {
type: X;
run: (interaction: SelectMenus[X], args: Record<T[number], string | undefined>) => any | Promise<any>;
}
interface ISelectMenuCommand<X extends keyof SelectMenus, T extends string[]> extends IDBasedCommand<T> {
commandType: "selectMenu";
type: X;
run: (interaction: SelectMenus[X], args: Record<T[number], string | undefined>) => any | Promise<any>;
isStringSelectMenuCommand: () => this is ISelectMenuCommand<"string", T>;
isUserSelectMenuCommand: () => this is ISelectMenuCommand<"user", T>;
isChannelSelectMenuCommand: () => this is ISelectMenuCommand<"channel", T>;
isRoleSelectMenuCommand: () => this is ISelectMenuCommand<"role", T>;
isMentionableSelectMenuCommand: () => this is ISelectMenuCommand<"mentionable", T>;
}
interface IButtonCommandOptions<T extends string[]> extends IDBasedCommandOptions<T> {
run: (interaction: ButtonInteraction<"cached">, args: Record<T[number], string | undefined>) => any | Promise<any>;
}
interface IButtonCommand<T extends string[]> extends IDBasedCommand<T> {
commandType: "button";
run: (interaction: ButtonInteraction<"cached">, args: Record<T[number], string | undefined>) => any | Promise<any>;
}
interface IModalCommandOptions<T extends string[]> extends IDBasedCommandOptions<T> {
run: (interaction: ModalSubmitInteraction<"cached">, args: Record<T[number], string | undefined>) => any | Promise<any>;
}
interface IModalCommand<T extends string[]> extends IDBasedCommand<T> {
commandType: "modal";
run: (interaction: ModalSubmitInteraction<"cached">, args: Record<T[number], string | undefined>) => any | Promise<any>;
}
type AnyCommand = MessageCommand<any> | SlashCommand | ContextMenuCommand<"user"> | ContextMenuCommand<"message"> | SelectMenuCommand<keyof SelectMenus, any> | ButtonCommand<any> | ModalCommand<any>;
interface ICommandManager {
stores: {
slash: Collection<string, ISlashCommand>;
contextMenuUser: Collection<string, IContextMenuCommand<"user">>;
contextMenuMessage: Collection<string, IContextMenuCommand<"message">>;
message: Collection<string, IMessageCommand<any>>;
selectMenu: Collection<string, ISelectMenuCommand<keyof SelectMenus, any>>;
button: Collection<string, IButtonCommand<any>>;
modal: Collection<string, IModalCommand<any>>;
};
ratelimits: {
user: Collection<string, {
command: string;
type: "slash" | "contextMenuUser" | "contextMenuMessage" | "message";
expires: number;
}[]>;
guild: Collection<string, {
command: string;
type: "slash" | "contextMenuUser" | "contextMenuMessage" | "message";
expires: number;
}[]>;
channel: Collection<string, {
command: string;
type: "slash" | "contextMenuUser" | "contextMenuMessage" | "message";
expires: number;
}[]>;
global: Collection<string, {
command: string;
type: "slash" | "contextMenuUser" | "contextMenuMessage" | "message";
expires: number;
}[]>;
};
run(intOrMsg: Interaction<"cached"> | Message, { commandName, precommand, postcommand, postrun, behavior, translations }: {
commandName?: string;
precommand?: (intOrMsg: Interaction<"cached"> | Message) => boolean;
postcommand?: (intOrMsg: Interaction<"cached"> | Message) => boolean;
postprocess?: (intOrMsg: Interaction<"cached"> | Message) => boolean;
postrun?: (intOrMsg: Interaction<"cached"> | Message) => boolean;
behavior?: "preferIgnore" | "preferReply" | "auto";
translations?: Partial<Record<"notallowed" | "ratelimit" | "unavailable", Partial<Record<LocaleString, string>>>>;
}): any | Promise<any>;
checkPermissions(command: MessageCommand<any> | SlashCommand | ContextMenuCommand<"user" | "message">, user: GuildMember | APIInteractionGuildMember): boolean;
ratelimit(command: MessageCommand<any> | SlashCommand | ContextMenuCommand<any>, userId: string): boolean;
parseArgs<T extends string>(args: string, format: T): MessageArguments<T>;
parseArgs<T extends string[]>(args: string, format: T): {
[K in T[number]]?: string;
} & {
id: string;
userId?: string;
};
parseArgs<T extends string | string[]>(args: string, format: T): Record<string, string | boolean | undefined>;
}
declare class CommandManager<Configs extends Record<string, any>, Emojis extends Record<string, Emoji>, Colors extends Record<string, ColorResolvable>> implements ICommandManager {
client: Bot<Configs, Emojis, Colors>;
constructor(client: Bot<Configs, Emojis, Colors>);
stores: {
slash: Collection<string, SlashCommand>;
contextMenuUser: Collection<string, ContextMenuCommand<"user">>;
contextMenuMessage: Collection<string, ContextMenuCommand<"message">>;
message: Collection<string, MessageCommand<any>>;
selectMenu: Collection<string, SelectMenuCommand<keyof SelectMenus, any>>;
button: Collection<string, ButtonCommand<any>>;
modal: Collection<string, ModalCommand<any>>;
};
ratelimits: {
user: Collection<string, {
command: string;
type: "message" | "slash" | "contextMenuUser" | "contextMenuMessage";
expires: number;
}[]>;
guild: Collection<string, {
command: string;
type: "message" | "slash" | "contextMenuUser" | "contextMenuMessage";
expires: number;
}[]>;
channel: Collection<string, {
command: string;
type: "message" | "slash" | "contextMenuUser" | "contextMenuMessage";
expires: number;
}[]>;
global: Collection<string, {
command: string;
type: "message" | "slash" | "contextMenuUser" | "contextMenuMessage";
expires: number;
}[]>;
};
destroy(): void;
run(intOrMsg: Interaction<"cached"> | Message, { commandName, precommand, postcommand, postprocess, postrun, behavior, translations }: {
commandName?: string;
precommand?: (intOrMsg: Interaction<"cached"> | Message) => boolean | Promise<boolean>;
postcommand?: (intOrMsg: Interaction<"cached"> | Message, command: AnyCommand) => boolean | Promise<boolean>;
postprocess?: (intOrMsg: Interaction<"cached"> | Message, command: AnyCommand) => boolean | Promise<boolean>;
postrun?: (intOrMsg: Interaction<"cached"> | Message, command: AnyCommand, result: any) => boolean | Promise<boolean>;
behavior?: "preferIgnore" | "preferReply" | "auto";
translations?: Partial<Record<"notallowed" | "ratelimit" | "unavailable", Partial<Record<LocaleString, string>>>>;
}): Promise<void | discord_js.OmitPartialGroupDMChannel<Message<boolean>> | discord_js.InteractionResponse<true>>;
checkPermissions(command: MessageCommand<any> | SlashCommand | ContextMenuCommand<"user" | "message">, user: GuildMember | APIInteractionGuildMember): boolean;
ratelimit(command: MessageCommand<any> | SlashCommand | ContextMenuCommand<"user" | "message">, userId: string): boolean;
parseArgs<T extends string>(args: string, format: T): MessageArguments<T>;
parseArgs<T extends string[]>(args: string, format: T): {
[K in T[number]]?: string;
} & {
id: string;
userId?: string;
};
}
declare class PluginManager<Configs extends Record<string, any>, Emojis extends Record<string, Emoji>, Colors extends Record<string, ColorResolvable>> implements IPluginManager {
client: Bot<Configs, Emojis, Colors>;
constructor(client: Bot<Configs, Emojis, Colors>);
store: Collection<string, Plugin>;
events: IPluginManager["events"];
commands: IPluginManager["commands"];
register(plugin: Plugin): void;
}
declare class MultiPageEmbedManager<Configs extends Record<string, any>, Emojis extends Record<string, Emoji>, Colors extends Record<string, ColorResolvable>> implements IMultiPageEmbedManager {
client: Bot<Configs, Emojis, Colors>;
constructor(client: Bot<Configs, Emojis, Colors>);
embeds: Collection<string, Omit<IMultiPageEmbedData, "id">>;
private handlers;
create(data: IMultiPageEmbedData, createEmbed: true, userId: string): MultiPageEmbed;
create(data: IMultiPageEmbedData, createEmbed: false): undefined;
get(embedId: string, userId: string): MultiPageEmbed | undefined;
delete(embedId: string): void;
private handle;
}
declare function createClient<Configs extends Record<string, any>, Emojis extends Record<string, Emoji>, Colors extends Record<string, ColorResolvable>>(options: BotOptions<Configs, Emojis, Colors>): Promise<Bot<Configs, Emojis, Colors>>;
declare class Bot<Configs extends Record<string, any>, Emojis extends Record<string, Emoji>, Colors extends Record<string, ColorResolvable>> extends Client<true> {
private configParser;
botOptions: PlainBotOptions<Configs, Emojis, Colors>;
private _botOptions;
logger: TypedLogger<["error", "warn", "debug", "log", "info"]>;
commands: CommandManager<Configs, Emojis, Colors>;
plugins: PluginManager<Configs, Emojis, Colors>;
multiPageEmbed: MultiPageEmbedManager<Configs, Emojis, Colors>;
get configs(): Configs;
get clientEmojis(): Emojis;
get clientColors(): Colors;
constructor(options: PlainBotOptions<Configs, Emojis, Colors>, configParser: ConfigParser<Configs>, BotBaseOptions: BotOptions<Configs, Emojis, Colors>);
emoji(name: keyof Emojis): Emojis[keyof Emojis];
color(name: keyof Colors): Colors[keyof Colors];
login(token?: string): Promise<string>;
destroy(): Promise<void>;
private load;
private loadCommands;
private loadEvents;
private loadPlugins;
}
export { type AdvancedCommandOptions, type AnyCommand, type BaseCommand, type BaseCommandOptions, Bot, type BotOptions, ButtonBuilder, ButtonCommand, ChannelSelectMenuBuilder, ContextMenuCommand, type Emoji, Event, type Help, type IButtonCommand, type IButtonCommandOptions, type ICommandManager, type IContextMenuCommand, type IContextMenuCommandOptions, type IDBasedCommand, type IDBasedCommandOptions, type IEvent, type IMessageCommand, type IMessageCommandOptions, type IModalCommand, type IModalCommandOptions, type IMultiPageEmbed, type IMultiPageEmbedData, type IMultiPageEmbedManager, type IPlugin, type IPluginManager, type ISelectMenuCommand, type ISelectMenuCommandOptions, type ISlashCommand, type ISlashCommandOptions, MentionableSelectMenuBuilder, type MessageArguments, MessageCommand, type MessageCommandOptions, ModalBuilder, ModalCommand, MultiPageEmbed, PermissionsMode, type PlainBotOptions, Plugin, type PluginCommandOptions, type PluginEventOptions, RoleSelectMenuBuilder, RunIn, SelectMenuCommand, type SelectMenus, SlashCommand, StringSelectMenuBuilder, UserSelectMenuBuilder, createClient as default };