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:
-
options
(Sequence[Option]
) –Options to the command.
-
sub_commands
(Dict[str, SubCommand]
) –Sub-commands of the command.
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}!")
- 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:
...
- When command has a sub-commands, callback will be ignored.
- Base information about your command: name, description, default member permissions and etc.
- Base information about your sub-command. The same fields with slash-command, but without guild, default member permissions, is nsfw, dm enabled flags.
- If sub-command have another sub-command, callback of parent sub-command will be ignored too.