Skip to content

Commands Addon


addon

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

C = TypeVar('C', bound=CommandContext) module-attribute

AddonHandler: TypeAlias = _AddonHandler[Any] module-attribute

AddonDecorator: TypeAlias = Callable[[AddonHandler], AddonHandler] module-attribute

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 name

  • 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

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

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

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)

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: