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>
.Should contain a SlashCommandBuilder The same as loadcommand_old
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:
An array of paths to directories that contain command files.
Optional
beforeload: (command: CommandFile) => undefined | void | CommandFileAn 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.
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
Loads a command into the bot's command registry.
This method takes a command of type
Commandfile
, validates the required properties (data
andexecute
). The processed command is then added to the bot's internal command collection.The
command
parameter should conform to theCommandfile
interface. It must contain:data
: The actual command data, which is expected to include aname
property and additional command-related properties. Thisdata
will be transpiled into aRESTPostAPIChatInputApplicationCommandsJSONBody
format using thetranspiledata
function.execute
: A function that defines what the command does when executed. This should be aPromise
returning function that accepts aChatInputCommandInteraction
parameter.