Constructors

Properties

client: Client<true>

Methods

  • Loads a command into the bot's command registry.

    This method takes a command of type Commandfile, validates the required properties (data and execute). The processed command is then added to the bot's internal command collection.

    The command parameter should conform to the Commandfile interface. It must contain:

    • data: The actual command data, which is expected to include a name property and additional command-related properties. This data will be transpiled into a RESTPostAPIChatInputApplicationCommandsJSONBody format using the transpiledata function.
    • execute: A function that defines what the command does when executed. This should be a Promise returning function that accepts a ChatInputCommandInteraction parameter.

    Parameters

    • command: CommandFile

      The command object that contains:

      • data: The command's data, which must include the name and optionally other properties like description, subcommands, options, etc. This data will be transpiled into a format compatible with Discord's Slash Commands API.
      • execute: A function that is executed when the command is triggered. It should accept a ChatInputCommandInteraction object and return a Promise<void>.

    Returns void

    If the command object is missing the required data or execute properties, an error will be logged.

    If the command.data does not have a valid name, it may cause issues in registering the command.

  • Loads multiple commands into the bot's command registry from the specified directories.

    This method iterates over the provided paths, reads the files in each directory, and loads commands that conform to the expected structure. Each file is validated to ensure that it contains a valid command format and the necessary data and execute properties. If any file is missing the required properties, errors are thrown.

    The data of each command is then processed, and any necessary transpiling is done to make it compatible with the bot's command registry. Once validated, each command is added to the bot's internal command collection. That can be accesed in the client.commands propriety from the main class (DiscordBot)

    The files must be placed in a 2 dimentional directory like: commands/utility/ping.ts or commands/server/ping.js. Where the path to commands gets passed to the method like:

    Parameters

    • paths: string[]

      An array of paths to directories that contain command files.

    • Optionalbeforeload: (command: CommandFile) => undefined | void | CommandFile

      An optional function that can be called before loading each command. It can be used to modify the command or perform additional checks. Or if you want to add a handler like a button handler or a modal handler. You can use

         declare module "discord-library" {
      export interface CommandFileProps {
      button?(interaction: ButtonInteraction): void | Promise<void>;
      }
      }

      Then if you use loadcommands you can load the custom button prop with it.

    Returns void

    loadcommands([path.join(__dirname, './commands')]);
    

    Asuming that the main file is in the same directory as the commands directory

    If any file is found that does not conform to the expected format (missing data or execute).

    loadcommands(['path/to/commands', 'path/to/another/commands']);
    

    In this example, the method will load all command files from the provided directories. Each file must export a valid command object with data and execute properties. *

  • Type Parameters

    • T extends keyof ClientEvents

    Parameters

    Returns void

  • Parameters

    • ...paths: string[]

      The path to the folder that contains the events files It loads the events into the discord bot as liseners You use this for telling the bot what do do when a user runs a command

    Returns void

  • It registers the commands to discord.

    Returns Promise<void>

    1.6 It is now smarter meaning that it will only register the commands only if they got changed or if the --refresh-all flag is used, or the refreshAll config is used.