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:

InteractionChannel module-attribute #

InteractionChannel = InteractionChannel

ResolvedOptionData module-attribute #

ResolvedOptionData = ResolvedOptionData

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.

channel_id class-attribute instance-attribute #

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

ID of the channel this command interaction event was triggered in.

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: Union[CommandType, int] = field(eq=False, hash=False, repr=True)

The type of the command.

entitlements class-attribute instance-attribute #

entitlements: Sequence[Entitlement] = field(eq=False, hash=False, repr=True)

For monetized apps, any entitlements for the invoking user, represents access to SKUs.

guild_id class-attribute instance-attribute #

guild_id: Optional[Snowflake] = field(eq=False, hash=False, repr=True)

ID of the guild this command interaction event was triggered in.

This will be None for command interactions triggered in DMs.

guild_locale class-attribute instance-attribute #

guild_locale: Optional[str] = field(eq=False, hash=False, repr=True)

The preferred language of the guild this command interaction was triggered in.

This will be None for command interactions triggered in DMs.

Note

This value can usually only be changed if [COMMUNITY] is in hikari.guilds.Guild.features for the guild and will otherwise default to en-US.

locale class-attribute instance-attribute #

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

The selected language of the user who triggered this command interaction.

member class-attribute instance-attribute #

member: Optional[InteractionMember] = field(eq=False, hash=False, repr=True)

The member who triggered this command interaction.

This will be None for command interactions triggered in DMs.

Note

This member object comes with the extra field permissions which contains the member's permissions in the current channel.

registered_guild_id class-attribute instance-attribute #

registered_guild_id: Optional[Snowflake] = field(eq=False, hash=False, repr=True)

ID of the guild the command is registered to.

user class-attribute instance-attribute #

user: User = field(eq=False, hash=False, repr=True)

The user who triggered this command interaction.

fetch_channel async #

fetch_channel() -> TextableChannel

Fetch the guild channel this was triggered in.

RETURNS DESCRIPTION
TextableChannel

The requested partial channel derived object of the channel this was triggered in.

RAISES DESCRIPTION
UnauthorizedError

If you are unauthorized to make the request (invalid/missing token).

ForbiddenError

If you are missing the hikari.permissions.Permissions.VIEW_CHANNEL permission in the channel.

NotFoundError

If the channel is not found.

RateLimitTooLongError

Raised in the event that a rate limit occurs that is longer than max_rate_limit when making a request.

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.

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.

fetch_guild async #

fetch_guild() -> Optional[RESTGuild]

Fetch the guild this interaction happened in.

RETURNS DESCRIPTION
Optional[RESTGuild]

Object of the guild this interaction happened in or None if this occurred within a DM channel.

RAISES DESCRIPTION
ForbiddenError

If you are not part of the guild.

NotFoundError

If the guild is not 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.

get_channel #

get_channel() -> Optional[TextableGuildChannel]

Get the guild channel this was triggered in from the cache.

Note

This will always return None for interactions triggered in a DM channel.

RETURNS DESCRIPTION
Optional[TextableGuildChannel]

The object of the guild channel that was found in the cache or None.

get_guild #

get_guild() -> Optional[GatewayGuild]

Get the object of this interaction's guild guild from the cache.

RETURNS DESCRIPTION
Optional[GatewayGuild]

The object of the guild if found, else None.

CommandInteraction #

Bases: BaseCommandInteraction, MessageResponseMixin[CommandResponseTypesT], ModalResponseMixin, PremiumResponseMixin

Represents a command interaction on Discord.

app_permissions class-attribute instance-attribute #

app_permissions: Optional[Permissions] = field(eq=False, hash=False, repr=False)

Permissions the bot has in this interaction's channel if it's in a guild.

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: Optional[ResolvedOptionData] = 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: Optional[Snowflake] = 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.

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: Optional[Sequence[Self]] = 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: Union[OptionType, int] = field(repr=True)

Type of this option.

value class-attribute instance-attribute #

value: Union[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.