Skip to content

Slash command

SlashCommand #

Bases: AppCommand

Represents a slash-command.

Parameters:

  • name (str) –

    The unique name of the command.

  • description (LocalizedOr[str] | None, default: 'No description' ) –

    A description of command.

  • display_name (LocalizedOr[str] | None, default: None ) –

    A display name of command. Can be localized.

  • guild (SnowflakeishOr[PartialGuild] | UndefinedType, default: UNDEFINED ) –

    The guild in which the command is available.

  • default_member_permissions (Permissions, default: Permissions.NONE ) –

    Permissions required to use the command, if any. Defaults to NONE.

  • is_dm_enabled (bool, default: False ) –

    Flag indicating whether the command is available in direct messages. Defaults to False.

  • is_nsfw (bool, default: False ) –

    Flag indicating whether the command should only be available in NSFW channels. Defaults to False.

  • options (Sequence[Option], default: () ) –

    Options to the command.

Attributes:

Example
class HelloCommand(SlashCommand):
    def __init__(self) -> None:
        super().__init__(name="hello", description="Say hi to bot")  # (1)

    async def callback(self, context: InteractionContext) -> None:
        await context.create_response(f"Hi, {context.user.mention}!")
  1. Base information about your command: name, description, default member permissions and etc.
class ABCCommand(SlashCommand):  # (1)
    def __init__(self) -> None:
        super().__init__(name="a")  # (2)

    @sub_command(name="b")  # (3)
    async def b_command(self, context: InteractionContext) -> None:
        ...  # (4)

    @b_command.sub_command(name="c")
    async def b_c_command(self, context: InteractionContext) -> None:
        ...
  1. When command has a sub-commands, callback will be ignored.
  2. Base information about your command: name, description, default member permissions and etc.
  3. Base information about your sub-command. The same fields with slash-command, but without guild, default member permissions, is nsfw, dm enabled flags.
  4. If sub-command have another sub-command, callback of parent sub-command will be ignored too.