hikari.interactions.command_interactions#

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

Module Contents#

hikari.interactions.command_interactions.COMMAND_RESPONSE_TYPES: Final[AbstractSet[CommandResponseTypesT]][source]#

Set of the response types which are valid for a command interaction.

This includes:

hikari.interactions.command_interactions.CommandResponseTypesT[source]#

Type-hint of the response types which are valid for a command interaction.

The following types are valid for this:

class hikari.interactions.command_interactions.InteractionChannel[source]#

Bases: hikari.channels.PartialChannel

Represents partial channels returned as resolved entities on interactions.

permissions: hikari.permissions.Permissions[source]#

Permissions the command’s executor has in this channel.

class hikari.interactions.command_interactions.ResolvedOptionData[source]#

Represents the resolved objects of entities referenced in a command’s options.

attachments: Mapping[hikari.snowflakes.Snowflake, hikari.messages.Attachment][source]#

Mapping of snowflake IDs to the attachment objects.

channels: Mapping[hikari.snowflakes.Snowflake, InteractionChannel][source]#

Mapping of snowflake IDs to the resolved option partial channel objects.

members: Mapping[hikari.snowflakes.Snowflake, hikari.interactions.base_interactions.InteractionMember][source]#

Mapping of snowflake IDs to the resolved option member objects.

messages: Mapping[hikari.snowflakes.Snowflake, hikari.messages.Message][source]#

Mapping of snowflake IDs to the resolved option partial message objects.

roles: Mapping[hikari.snowflakes.Snowflake, hikari.guilds.Role][source]#

Mapping of snowflake IDs to the resolved option role objects.

users: Mapping[hikari.snowflakes.Snowflake, hikari.users.User][source]#

Mapping of snowflake IDs to the resolved option user objects.

class hikari.interactions.command_interactions.CommandInteractionOption[source]#

Represents the options passed for a command interaction.

name: str[source]#

Name of this option.

type: Union[hikari.commands.OptionType, int][source]#

Type of this option.

value: Union[hikari.snowflakes.Snowflake, str, int, bool, None][source]#

Value provided for this option.

Either CommandInteractionOption.value or 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.

options: Optional[Sequence[CommandInteractionOption]][source]#

Options provided for this option.

Either CommandInteractionOption.value or 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.

class hikari.interactions.command_interactions.AutocompleteInteractionOption[source]#

Bases: CommandInteractionOption

Represents the options passed for a command autocomplete interaction.

is_focused: bool[source]#

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.

options: Optional[Sequence[AutocompleteInteractionOption]][source]#

Options provided for this option.

Either AutocompleteInteractionOption.value or AutocompleteInteractionOption.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.

AutocompleteInteractionOption.is_focused will be True for the value being autocompleted.

class hikari.interactions.command_interactions.BaseCommandInteraction[source]#

Bases: hikari.interactions.base_interactions.PartialInteraction

Represents a base command interaction on Discord.

May be a command interaction or an autocomplete interaction.

channel_id: hikari.snowflakes.Snowflake[source]#

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

guild_id: Optional[hikari.snowflakes.Snowflake][source]#

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

This will be None for command interactions triggered in DMs.

guild_locale: Optional[str][source]#

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.

member: Optional[hikari.interactions.base_interactions.InteractionMember][source]#

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.

user: hikari.users.User[source]#

The user who triggered this command interaction.

locale: str[source]#

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

command_id: hikari.snowflakes.Snowflake[source]#

ID of the command being invoked.

command_name: str[source]#

Name of the command being invoked.

command_type: Union[hikari.commands.CommandType, int][source]#

The type of the command.

async fetch_channel()[source]#

Fetch the guild channel this was triggered in.

Returns
hikari.channels.TextableChannel

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

Raises
hikari.errors.UnauthorizedError

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

hikari.errors.ForbiddenError

If you are missing the READ_MESSAGES permission in the channel.

hikari.errors.NotFoundError

If the channel is not found.

hikari.errors.RateLimitTooLongError

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

hikari.errors.RateLimitTooLongError

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

hikari.errors.RateLimitedError

Usually, Hikari will handle and retry on hitting rate-limits automatically. This includes most bucket-specific rate-limits and global rate-limits. In some rare edge cases, however, Discord implements other undocumented rules for rate-limiting, such as limits per attribute. These cannot be detected or handled normally by Hikari due to their undocumented nature, and will trigger this exception if they occur.

hikari.errors.InternalServerError

If an internal error occurs on Discord while handling the request.

get_channel()[source]#

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
typing.Optional[hikari.channels.TextableGuildChannel]

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

async fetch_command()[source]#

Fetch the command which triggered this interaction.

Returns
hikari.commands.PartialCommand

Object of this interaction’s command.

Raises
hikari.errors.ForbiddenError

If you cannot access the target command.

hikari.errors.NotFoundError

If the command isn’t found.

hikari.errors.UnauthorizedError

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

hikari.errors.RateLimitTooLongError

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

hikari.errors.RateLimitedError

Usually, Hikari will handle and retry on hitting rate-limits automatically. This includes most bucket-specific rate-limits and global rate-limits. In some rare edge cases, however, Discord implements other undocumented rules for rate-limiting, such as limits per attribute. These cannot be detected or handled normally by Hikari due to their undocumented nature, and will trigger this exception if they occur.

hikari.errors.InternalServerError

If an internal error occurs on Discord while handling the request.

async fetch_guild()[source]#

Fetch the guild this interaction happened in.

Returns
typing.Optional[hikari.guilds.RESTGuild]

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

Raises
hikari.errors.ForbiddenError

If you are not part of the guild.

hikari.errors.NotFoundError

If the guild is not found.

hikari.errors.UnauthorizedError

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

hikari.errors.RateLimitTooLongError

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

hikari.errors.RateLimitedError

Usually, Hikari will handle and retry on hitting rate-limits automatically. This includes most bucket-specific rate-limits and global rate-limits. In some rare edge cases, however, Discord implements other undocumented rules for rate-limiting, such as limits per attribute. These cannot be detected or handled normally by Hikari due to their undocumented nature, and will trigger this exception if they occur.

hikari.errors.InternalServerError

If an internal error occurs on Discord while handling the request.

get_guild()[source]#

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

Returns
typing.Optional[hikari.guilds.GatewayGuild]

The object of the guild if found, else None.

class hikari.interactions.command_interactions.CommandInteraction[source]#

Bases: BaseCommandInteraction, hikari.interactions.base_interactions.MessageResponseMixin[CommandResponseTypesT], hikari.interactions.base_interactions.ModalResponseMixin

Represents a command interaction on Discord.

app_permissions: Optional[hikari.permissions.Permissions][source]#

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

options: Optional[Sequence[CommandInteractionOption]][source]#

Parameter values provided by the user invoking this command.

resolved: Optional[ResolvedOptionData][source]#

Mappings of the objects resolved for the provided command options.

target_id: Optional[hikari.snowflakes.Snowflake][source]#

The target of the command. Only available if the command is a context menu command.

build_response()[source]#

Get a message response builder for use in the REST server flow.

Note

For interactions received over the gateway CommandInteraction.create_initial_response should be used to set the interaction response message.

Returns
hikari.api.special_endpoints.InteractionMessageBuilder

Interaction message response builder object.

Examples

async def handle_command_interaction(interaction: CommandInteraction) -> InteractionMessageBuilder:
    return (
        interaction
        .build_response()
        .add_embed(Embed(description="Hi there"))
        .set_content("Konnichiwa")
    )
build_deferred_response()[source]#

Get a deferred message response builder for use in the REST server flow.

Note

For interactions received over the gateway 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.

Returns
hikari.api.special_endpoints.InteractionMessageBuilder

Deferred interaction message response builder object.

class hikari.interactions.command_interactions.AutocompleteInteraction[source]#

Bases: BaseCommandInteraction

Represents an autocomplete interaction on Discord.

options: Sequence[AutocompleteInteractionOption][source]#

Parameter values provided by the user invoking this command.

build_response(choices)[source]#

Get a message response builder for use in the REST server flow.

Note

For interactions received over the gateway AutocompleteInteraction.create_response should be used to set the interaction response.

Returns
hikari.api.special_endpoints.InteractionAutocompleteBuilder

Interaction autocomplete response builder object.

Examples

async def handle_autocomplete_interaction(interaction: AutocompleteInteraction) -> InteractionAutocompleteBuilder:
    return (
        interaction
        .build_response(
            [
                CommandChoice(name="foo", value="a"),
                CommandChoice(name="bar", value="b"),
                CommandChoice(name="baz", value="c"),
            ]
        )
    )
async create_response(choices)[source]#

Create a response for this autocomplete interaction.