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:
InteractionChannel module-attribute
#
InteractionChannel = InteractionChannel
Deprecated alias of hikari.interactions.base_interactions.InteractionChannel
.
ResolvedOptionData module-attribute
#
ResolvedOptionData = ResolvedOptionData
Deprecated alias of hikari.interactions.base_interactions.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 #
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.
channel_id class-attribute
instance-attribute
#
ID of the channel this command interaction event was triggered in.
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: 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
#
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
#
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
#
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
#
ID of the guild the command is registered to.
user class-attribute
instance-attribute
#
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 |
NotFoundError | If the channel is not found. |
RateLimitTooLongError | Raised in the event that a rate limit occurs that is longer than |
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. |
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. |
fetch_guild async
#
Fetch the guild this interaction happened in.
RETURNS | DESCRIPTION |
---|---|
Optional[RESTGuild] | Object of the guild this interaction happened in or |
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 |
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 |
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 |
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
#
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.
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: Union[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.