Skip to content

Commands Addon


addon

logger = logging.getLogger('scurrypy') module-attribute

AddonHandler = Callable[[CommandContext], Awaitable[None]]

AddonDecorator = Callable[[AddonHandler], AddonHandler]

AnyCommand = SlashCommandPart | UserCommandPart | MessageCommandPart | SlashCommandFamilyPart

DuplicateCommand

Bases: ScurrypyError


              flowchart TD
              scurrypy.ext.commands.addon.DuplicateCommand[DuplicateCommand]
              scurrypy.core.exceptions.ScurrypyError[ScurrypyError]

                              scurrypy.core.exceptions.ScurrypyError --> scurrypy.ext.commands.addon.DuplicateCommand
                


              click scurrypy.ext.commands.addon.DuplicateCommand href "" "scurrypy.ext.commands.addon.DuplicateCommand"
              click scurrypy.core.exceptions.ScurrypyError href "" "scurrypy.core.exceptions.ScurrypyError"
            

Raised when two commands of the same name have been registered.

CommandsAddon

Bases: Addon


              flowchart TD
              scurrypy.ext.commands.addon.CommandsAddon[CommandsAddon]
              scurrypy.bases.addon.Addon[Addon]

                              scurrypy.bases.addon.Addon --> scurrypy.ext.commands.addon.CommandsAddon
                


              click scurrypy.ext.commands.addon.CommandsAddon href "" "scurrypy.ext.commands.addon.CommandsAddon"
              click scurrypy.bases.addon.Addon href "" "scurrypy.bases.addon.Addon"
            

Addon that implements automatic registering and decorating command interactions.

Parameters:

  • client (Client) –

    the bot client object

  • sync_commands (bool, default: True ) –

    whether to sync commands. Defaults to True.

bot = client instance-attribute

application_id = application_id instance-attribute

sync_commands = sync_commands instance-attribute

slash_handlers: dict[str, AddonHandler] = {} instance-attribute

Mapping of command names to handler.

message_handlers: dict[str, AddonHandler] = {} instance-attribute

Mapping of message command names to handler.

user_handlers: dict[str, AddonHandler] = {} instance-attribute

Mapping of user command names to handler.

autocomplete_handlers: dict[str, AddonHandler] = {} instance-attribute

Mapping of autocomplete keys to handler.

on_startup

Sets up the addon with the client.

slash_command

Register and route a slash command.

Parameters:

  • name (str) –

    command or command family name (if a subcommand family group)

  • description (str) –

    command description

  • handler (AddonHandler, default: None ) –

    callback for the command (if not a decorator)

  • options (list[CommandOptionPart], default: None ) –

    list of command options

  • guild_ids (list[Snowflake], default: None ) –

    list of guild IDs for guild commands or omit for global

Raises:

subcommand_group

Register and route a slash command.

Parameters:

  • name (str) –

    command or command family name (if a subcommand family group)

  • description (str) –

    command description

  • options (list[SubcommandGroupPart | SubcommandPart]) –

    list of subcommand options

  • handler (AddonHandler, default: None ) –

    callback for the command (if not a decorator)

  • guild_ids (list[Snowflake], default: None ) –

    list of guild IDs for guild commands or omit for global

Raises:

user_command

Register and route a user command.

Parameters:

  • name (str) –

    command name

  • handler (AddonHandler, default: None ) –

    callback for the command (if not a decorator)

  • guild_ids (list[Snowflake], default: None ) –

    list of guild IDs for guild commands or omit for global

Raises:

message_command

Register and route a message command.

Parameters:

  • name (str) –

    command name

  • handler (AddonHandler, default: None ) –

    callback for the command (if not a decorator)

  • guild_ids (list[Snowflake], default: None ) –

    list of guild IDs for guild commands or omit for global

Raises:

autocomplete

Register and route an autocomplete interaction.

Parameters:

  • command_name (str) –

    name of command to autocomplete

  • option_name (str) –

    name of option to autocomplete

  • handler (AddonHandler, default: None ) –

    callback for the command (if not a decorator)

Raises:

clear_commands

Clear a guild's or global commands (slash, message, and user).

Parameters:

  • guild_ids (list[Snowflake], default: None ) –

    list of guild IDs for guild commands or omit for global

dispatch async

Dispatch a response to an INTERACTION_CREATE event.

Raises:

Parameters:

  • event (JsonQuery) –

    interaction event object