hikari.interactions.command_interactions#
Models and enums used for Discord’s Slash Commands interaction flow.
Module Contents#
- 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.Deprecated since version 2.0.0.dev118: Passing `hikari.commands.CommandChoice`s here instead of `hikari.api.special_endpoints.AutocompleteChoiceBuilder`s.
- Returns:
hikari.api.special_endpoints.InteractionAutocompleteBuilder
Interaction autocomplete response builder object.
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"), ] ) )
- class hikari.interactions.command_interactions.AutocompleteInteractionOption[source]#
Bases:
CommandInteractionOption
Represents the options passed for a command autocomplete interaction.
- 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.
- command_id: hikari.snowflakes.Snowflake[source]#
ID of the command being invoked.
- command_type: hikari.commands.CommandType | int[source]#
The type of the command.
- guild_id: hikari.snowflakes.Snowflake | None[source]#
ID of the guild this command interaction event was triggered in.
This will be
None
for command interactions triggered in DMs.
- guild_locale: str | None[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 inhikari.guilds.Guild.features
for the guild and will otherwise default toen-US
.
- member: hikari.interactions.base_interactions.InteractionMember | None[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.
- 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.InternalServerError
If an internal error occurs on Discord while handling the request.
- 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.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.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
.
- 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: hikari.permissions.Permissions | None[source]#
Permissions the bot has in this interaction’s channel if it’s in a guild.
- options: Sequence[CommandInteractionOption] | None[source]#
Parameter values provided by the user invoking this command.
- resolved: hikari.interactions.base_interactions.ResolvedOptionData | None[source]#
Mappings of the objects resolved for the provided command options.
- target_id: hikari.snowflakes.Snowflake | None[source]#
The target of the command. Only available if the command is a context menu command.
- 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.
Examples
async def handle_command_interaction(interaction: CommandInteraction) -> InteractionMessageBuilder: yield interaction.build_deferred_response() await interaction.edit_initial_response("Pong!")
- 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") )
- class hikari.interactions.command_interactions.CommandInteractionOption[source]#
Represents the options passed for a command interaction.
- options: Sequence[typing_extensions.Self] | None[source]#
Options provided for this option.
Either
CommandInteractionOption.value
orCommandInteractionOption.options
will be provided withvalue
being provided when an option is provided as a parameter with a value andoptions
being provided when an option donates a subcommand or group.
- type: hikari.commands.OptionType | int[source]#
Type of this option.
- value: hikari.snowflakes.Snowflake | str | int | bool | None[source]#
Value provided for this option.
Either
CommandInteractionOption.value
orCommandInteractionOption.options
will be provided withvalue
being provided when an option is provided as a parameter with a value andoptions
being provided when an option donates a subcommand or group.
- 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: