Skip to content

Command handler

CommandHandler #

Handles command building and synchronization for a bot application.

This class is responsible for application commands. It registers commands, synchronizes them with the Discord API.

Attributes:

  • commands (Dict[str, AppCommand]) –

    Dictionary that stores the AppCommand instances, keyed by their names.

  • app_commands (Dict[Snowflake, AppCommand]) –

    Dictionary that stores AppCommand instances, keyed by their application ID

get_command #

get_command(context: InteractionContext) -> SlashCommand | ContextMenuCommand | SubCommand

Get command from context.

Because sub-commands are passed through the options field of the received interaction, the arguments for the command have already been processed and are located in the context.arguments field (InteractionContext.arguments).

load_folder #

load_folder(directory: PathLike[str]) -> None

Load commands from folder.

sync async #

sync(*, debug: bool = False) -> None

Synchronizes the builders of commands with the Discord API for the bot application.

This method will handle both global commands and guild-specific commands, ensuring they are up-to-date with the currently stored command builders.

Parameters:

  • debug (bool, default: False ) –

    A boolean flag that, when set to True, enables more verbose logging of the synchronization process for debugging purposes.