Skip to content

hikari.interactions.command_interactions#

Models and enums used for Discord's Slash Commands interaction flow.

COMMAND_RESPONSE_TYPES module-attribute #

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 #

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.

TYPE: Sequence[AutocompleteChoiceBuilder]

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.

TYPE: Sequence[AutocompleteChoiceBuilder]

AutocompleteInteractionOption #

Bases: CommandInteractionOption

Represents the options passed for a command autocomplete interaction.

is_focused class-attribute instance-attribute #

is_focused: bool = field(default=False, repr=True)

Whether this option is the currently focused option for autocomplete.

Focused options are not guaranteed to be parsed so the value may be a string even if the option type says otherwise.

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 #

command_id: Snowflake = field(
    eq=False, hash=False, repr=True
)

ID of the command being invoked.

command_name class-attribute instance-attribute #

command_name: str = field(eq=False, hash=False, repr=True)

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 #

registered_guild_id: Snowflake | None = field(
    eq=False, hash=False, repr=True
)

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 max_rate_limit when making a request.

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 #

target_id: Snowflake | None = field(
    default=None, eq=False, hash=False, repr=True
)

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 #

target_message_id: Snowflake | None = field(
    eq=False, hash=False, repr=True
)

The ID of the message the command was run on, present only on message command interactions.

target_user class-attribute instance-attribute #

target_user: User | None = field(
    eq=False, hash=False, repr=True
)

The user the command was run on, present only on user command interactions.

CommandInteractionOption #

Represents the options passed for a command interaction.

name class-attribute instance-attribute #

name: str = field(repr=True)

Name of this option.

options class-attribute instance-attribute #

options: Sequence[Self] | None = field(repr=True)

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: Snowflake | str | int | float | bool | None = field(
    repr=True
)

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.