hikari.interactions.command_interactions
#
Models and enums used for Discord's Slash Commands interaction flow.
COMMAND_RESPONSE_TYPES module-attribute
#
COMMAND_RESPONSE_TYPES: Final[
AbstractSet[CommandResponseTypesT]
] = frozenset([MESSAGE_CREATE, DEFERRED_MESSAGE_CREATE])
Set of the response types which are valid for a command interaction.
This includes:
CommandResponseTypesT module-attribute
#
CommandResponseTypesT = Literal[
MESSAGE_CREATE, 4, DEFERRED_MESSAGE_CREATE, 5
]
Type-hint of the response types which are valid for a command interaction.
The following types are valid for this:
AutocompleteInteraction #
Bases: BaseCommandInteraction
Represents an autocomplete interaction on Discord.
options class-attribute
instance-attribute
#
options: Sequence[AutocompleteInteractionOption] = field(
eq=False, hash=False, repr=True
)
Parameter values provided by the user invoking this command.
build_response #
build_response(
choices: Sequence[AutocompleteChoiceBuilder],
) -> InteractionAutocompleteBuilder
Get a message response builder for use in the REST server flow.
Note
For interactions received over the gateway hikari.interactions.command_interactions.AutocompleteInteraction.create_response
should be used to set the interaction response.
PARAMETER | DESCRIPTION |
---|---|
choices | The choices for the autocomplete. |
Examples:
async def handle_autocomplete_interaction(
interaction: AutocompleteInteraction,
) -> InteractionAutocompleteBuilder:
return interaction.build_response(
[
AutocompleteChoiceBuilder(name="foo", value="a"),
AutocompleteChoiceBuilder(name="bar", value="b"),
AutocompleteChoiceBuilder(name="baz", value="c"),
]
)
RETURNS | DESCRIPTION |
---|---|
InteractionAutocompleteBuilder | Interaction autocomplete response builder object. |
create_response async
#
create_response(
choices: Sequence[AutocompleteChoiceBuilder],
) -> None
Create a response for this autocomplete interaction.
PARAMETER | DESCRIPTION |
---|---|
choices | The choices for the autocomplete. |
AutocompleteInteractionOption #
Bases: CommandInteractionOption
Represents the options passed for a command autocomplete interaction.
BaseCommandInteraction #
Bases: PartialInteraction
Represents a base command interaction on Discord.
May be a command interaction or an autocomplete interaction.
command_id class-attribute
instance-attribute
#
ID of the command being invoked.
command_name class-attribute
instance-attribute
#
Name of the command being invoked.
command_type class-attribute
instance-attribute
#
command_type: CommandType | int = field(
eq=False, hash=False, repr=True
)
The type of the command.
registered_guild_id class-attribute
instance-attribute
#
ID of the guild the command is registered to.
fetch_command async
#
fetch_command() -> PartialCommand
Fetch the command which triggered this interaction.
RETURNS | DESCRIPTION |
---|---|
PartialCommand | Object of this interaction's command. |
RAISES | DESCRIPTION |
---|---|
ForbiddenError | If you cannot access the target command. |
NotFoundError | If the command isn't found. |
UnauthorizedError | If you are unauthorized to make the request (invalid/missing token). |
RateLimitTooLongError | Raised in the event that a rate limit occurs that is longer than |
InternalServerError | If an internal error occurs on Discord while handling the request. |
CommandInteraction #
Bases: BaseCommandInteraction
, MessageResponseMixin[CommandResponseTypesT]
, ModalResponseMixin
, PremiumResponseMixin
Represents a command interaction on Discord.
app_permissions class-attribute
instance-attribute
#
app_permissions: Permissions = field(
eq=False, hash=False, repr=False
)
Permissions the bot has in this interaction's channel.
options class-attribute
instance-attribute
#
options: Sequence[CommandInteractionOption] = field(
eq=False, hash=False, repr=True
)
Parameter values provided by the user invoking this command.
resolved class-attribute
instance-attribute
#
resolved: ResolvedOptionData | None = field(
eq=False, hash=False, repr=False
)
Mappings of the objects resolved for the provided command options.
target_id class-attribute
instance-attribute
#
The target of the command. Only available if the command is a context menu command.
build_deferred_response #
build_deferred_response() -> InteractionDeferredBuilder
Get a deferred message response builder for use in the REST server flow.
Note
For interactions received over the gateway hikari.interactions.command_interactions.CommandInteraction.create_initial_response
should be used to set the interaction response message.
Note
Unlike hikari.api.special_endpoints.InteractionMessageBuilder
, the result of this call can be returned as is without any modifications being made to it.
Examples:
async def handle_command_interaction(
interaction: CommandInteraction,
) -> InteractionMessageBuilder:
yield interaction.build_deferred_response()
await interaction.edit_initial_response("Pong!")
RETURNS | DESCRIPTION |
---|---|
InteractionMessageBuilder | Deferred interaction message response builder object. |
build_response #
build_response() -> InteractionMessageBuilder
Get a message response builder for use in the REST server flow.
Note
For interactions received over the gateway hikari.interactions.command_interactions.CommandInteraction.create_initial_response
should be used to set the interaction response message.
Examples:
async def handle_command_interaction(
interaction: CommandInteraction,
) -> InteractionMessageBuilder:
return (
interaction.build_response()
.add_embed(Embed(description="Hi there"))
.set_content("Konnichiwa")
)
RETURNS | DESCRIPTION |
---|---|
InteractionMessageBuilder | Interaction message response builder object. |
CommandInteractionMetadata #
Bases: PartialInteractionMetadata
The interaction metadata for a command initiated message.
target_message_id class-attribute
instance-attribute
#
The ID of the message the command was run on, present only on message command interactions.
CommandInteractionOption #
Represents the options passed for a command interaction.
options class-attribute
instance-attribute
#
Options provided for this option.
Either hikari.interactions.command_interactions.CommandInteractionOption.value
or hikari.interactions.command_interactions.CommandInteractionOption.options
will be provided with value
being provided when an option is provided as a parameter with a value and options
being provided when an option donates a subcommand or group.
type class-attribute
instance-attribute
#
type: OptionType | int = field(repr=True)
Type of this option.
value class-attribute
instance-attribute
#
Value provided for this option.
Either hikari.interactions.command_interactions.CommandInteractionOption.value
or hikari.interactions.command_interactions.CommandInteractionOption.options
will be provided with value
being provided when an option is provided as a parameter with a value and options
being provided when an option donates a subcommand or group.