UNPKG

@wilcosp/rex

Version:

Rex is an automated command manager for discord js

86 lines (85 loc) 3.08 kB
/*! * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at https://mozilla.org/MPL/2.0/. */ import { Client } from "discord.js"; import { ZodError } from "zod"; type ErrorFun = (this: null, error: Error | ZodError | unknown) => void; /** * The Rex command manager, the manager will import all commands, register them and will handle them when an interaction is received */ export declare class RexCommandManager { readonly client: Client; private config; private commands; private components; private modals; private fetchedCommands; private DSCommandManager?; private initializing; private registerQueue; /** * * @param client the discord js bot client * @param config.slashCommandsDir the directory/folder where all slash commands are stored adjacent from the entry file * @param config.contextMenuDir the directory/folder where all content menu commands with execute functions are stored adjacent from the entry file (optional) * @param config.componentsDir the directory/folder where all components with execute functions are stored adjacent from the entry file (optional) * @param config.modalDir the directory/folder where all modals with execute functions are stored adjacent from the entry file (optional) * @param config.log whether to log some of the auctions manager is doing at start up (can be expanded in future updates) (optional) */ constructor(client: Client, config: { slashCommandsDir: string; contextMenuDir?: string; componentsDir?: string; modalDir?: string; log?: boolean; }); private errorHandler; private emitError; /** * register a callback for when an error happens somewhere in this library or from a command * @param fun a callback that can handle an error */ onError(fun: ErrorFun): void; /** * (re)initializes all commands */ private initializeCommands; /** * fetch all guilds this shard/bot could've commands in * @returns all guild IDs */ private fetchGuilds; /** * Fetches all commands from discord * @returns map with all fetched commands * @ignore internal */ private getFetchedCommands; private loadCommands; private registerCommand; private handleSlashCommand; private handleAutoComplete; private handleContextMenuCommand; /** * unregister commands that have been removed * @ignore internal */ private unregisterCommands; private loadComponents; private handleComponent; private loadModals; private handleModal; private logger; } /** * imports cjs & esm, for esm when running under cjs it will use the esmImport * @param file the file to be imported * @returns the imported javascript * @ignore internal */ export declare function importer<Expected>(file: string): Promise<Expected | { default: Expected; }>; export {};