hikari.interactions.component_interactions
#
Models and enums used for Discord's Components interaction flow.
COMPONENT_RESPONSE_TYPES module-attribute
#
COMPONENT_RESPONSE_TYPES: Final[AbstractSet[ComponentResponseTypesT]] = (
frozenset([*_DEFERRED_TYPES, *_IMMEDIATE_TYPES])
)
Set of the response types which are valid for a component interaction.
This includes:
ComponentResponseTypesT module-attribute
#
ComponentResponseTypesT = Union[_ImmediateTypesT, _DeferredTypesT]
Type-hint of the response types which are valid for a component interaction.
The following types are valid for this:
ComponentInteraction #
Bases: MessageResponseMixin[ComponentResponseTypesT]
, ModalResponseMixin
, PremiumResponseMixin
Represents a component interaction on Discord.
app class-attribute
instance-attribute
#
Client application that models may use for procedures.
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.
application_id class-attribute
instance-attribute
#
ID of the application this interaction belongs to.
channel_id class-attribute
instance-attribute
#
ID of the channel this interaction was triggered in.
component_type class-attribute
instance-attribute
#
component_type: Union[ComponentType, int] = field(eq=False)
The type of component which triggers this interaction.
Note
This will never be hikari.components.ButtonStyle.LINK
as link buttons don't trigger interactions.
custom_id class-attribute
instance-attribute
#
Developer defined ID of the component which triggered this interaction.
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 interaction was triggered in.
This will be None
for component interactions triggered in DMs.
guild_locale class-attribute
instance-attribute
#
The preferred language of the guild this component interaction was triggered in.
This will be None
for component 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
.
id class-attribute
instance-attribute
#
ID of this entity.
locale class-attribute
instance-attribute
#
The selected language of the user who triggered this component interaction.
member class-attribute
instance-attribute
#
member: Optional[InteractionMember] = field(eq=False, hash=False, repr=True)
The member who triggered this interaction.
This will be None
for interactions triggered in DMs.
Note
This member object comes with the extra field permissions
which contains the member's permissions in the current channel.
message class-attribute
instance-attribute
#
Object of the message the components for this interaction are attached to.
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.
token class-attribute
instance-attribute
#
The interaction's token.
type class-attribute
instance-attribute
#
type: Union[InteractionType, int] = field(eq=False, repr=True)
The type of interaction this is.
user class-attribute
instance-attribute
#
The user who triggered this interaction.
values class-attribute
instance-attribute
#
Sequence of the values which were selected for a select menu component.
version class-attribute
instance-attribute
#
Version of the interaction system this interaction is under.
build_deferred_response #
build_deferred_response(type_: _DeferredTypesT) -> InteractionDeferredBuilder
Get a deferred message response builder for use in the REST server flow.
Note
For interactions received over the gateway hikari.interactions.component_interactions.ComponentInteraction.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.
PARAMETER | DESCRIPTION |
---|---|
type_ | The type of deferred response this should be. This may be one of the following: TYPE: |
RETURNS | DESCRIPTION |
---|---|
InteractionDeferredBuilder | Deferred interaction message response builder object. |
build_modal_response #
build_modal_response(title: str, custom_id: str) -> InteractionModalBuilder
Create a builder for a modal interaction response.
PARAMETER | DESCRIPTION |
---|---|
title | The title that will show up in the modal. TYPE: |
custom_id | Developer set custom ID used for identifying interactions with this modal. TYPE: |
RETURNS | DESCRIPTION |
---|---|
InteractionModalBuilder | The interaction modal response builder object. |
build_response #
build_response(type_: _ImmediateTypesT) -> InteractionMessageBuilder
Get a message response builder for use in the REST server flow.
Note
For interactions received over the gateway hikari.interactions.component_interactions.ComponentInteraction.create_initial_response
should be used to set the interaction response message.
PARAMETER | DESCRIPTION |
---|---|
type_ | The type of immediate response this should be. This may be one of the following: TYPE: |
Examples:
async def handle_component_interaction(interaction: ComponentInteraction) -> InteractionMessageBuilder:
return (
interaction
.build_response(ResponseType.MESSAGE_UPDATE)
.add_embed(Embed(description="Hi there"))
.set_content("Konnichiwa")
)
RETURNS | DESCRIPTION |
---|---|
InteractionMessageBuilder | Interaction message response builder object. |
create_initial_response async
#
create_initial_response(
response_type: _CommandResponseTypesT,
content: UndefinedOr[Any] = undefined.UNDEFINED,
*,
flags: Union[int, MessageFlag, UndefinedType] = undefined.UNDEFINED,
tts: UndefinedOr[bool] = undefined.UNDEFINED,
attachment: UndefinedNoneOr[Resourceish] = undefined.UNDEFINED,
attachments: UndefinedNoneOr[Sequence[Resourceish]] = undefined.UNDEFINED,
component: UndefinedNoneOr[ComponentBuilder] = undefined.UNDEFINED,
components: UndefinedNoneOr[
Sequence[ComponentBuilder]
] = undefined.UNDEFINED,
embed: UndefinedNoneOr[Embed] = undefined.UNDEFINED,
embeds: UndefinedNoneOr[Sequence[Embed]] = undefined.UNDEFINED,
mentions_everyone: UndefinedOr[bool] = undefined.UNDEFINED,
user_mentions: UndefinedOr[
Union[SnowflakeishSequence[PartialUser], bool]
] = undefined.UNDEFINED,
role_mentions: UndefinedOr[
Union[SnowflakeishSequence[PartialRole], bool]
] = undefined.UNDEFINED
) -> None
Create the initial response for this interaction.
Warning
Calling this on an interaction which already has an initial response will result in this raising a hikari.errors.NotFoundError
. This includes if the REST interaction server has already responded to the request.
PARAMETER | DESCRIPTION |
---|---|
response_type | The type of interaction response this is. TYPE: |
content | If provided, the message contents. If If this is a TYPE: |
attachment | If provided, the message attachment. This can be a resource, or string of a path on your computer or a URL. TYPE: |
attachments | If provided, the message attachments. These can be resources, or strings consisting of paths on your computer or URLs. TYPE: |
component | If provided, builder object of the component to include in this message. TYPE: |
components | If provided, a sequence of the component builder objects to include in this message. TYPE: |
embed | If provided, the message embed. TYPE: |
embeds | If provided, the message embeds. TYPE: |
flags | If provided, the message flags this response should have. As of writing the only message flags which can be set here are TYPE: |
tts | If provided, whether the message will be read out by a screen reader using Discord's TTS (text-to-speech) system. TYPE: |
mentions_everyone | If provided, whether the message should parse @everyone/@here mentions. TYPE: |
user_mentions | If provided, and TYPE: |
role_mentions | If provided, and TYPE: |
RAISES | DESCRIPTION |
---|---|
ValueError | If more than 100 unique objects/entities are passed for |
TypeError | If both |
BadRequestError | This may be raised in several discrete situations, such as messages being empty with no embeds; messages with more than 2000 characters in them, embeds that exceed one of the many embed limits; invalid image URLs in embeds. |
UnauthorizedError | If you are unauthorized to make the request (invalid/missing token). |
NotFoundError | If the interaction is not found or if the interaction's initial response has already been created. |
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. |
create_modal_response async
#
create_modal_response(
title: str,
custom_id: str,
component: UndefinedOr[ComponentBuilder] = undefined.UNDEFINED,
components: UndefinedOr[Sequence[ComponentBuilder]] = undefined.UNDEFINED,
) -> None
Create a response by sending a modal.
PARAMETER | DESCRIPTION |
---|---|
title | The title that will show up in the modal. TYPE: |
custom_id | Developer set custom ID used for identifying interactions with this modal. TYPE: |
component | A component builder to send in this modal. TYPE: |
components | A sequence of component builders to send in this modal. TYPE: |
RAISES | DESCRIPTION |
---|---|
ValueError | If both |
create_premium_required_response async
#
create_premium_required_response() -> None
Create a response by sending a premium upsell.
RAISES | DESCRIPTION |
---|---|
ForbiddenError | If you cannot access the target interaction. |
NotFoundError | If the initial response 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. |
delete_initial_response async
#
delete_initial_response() -> None
Delete the initial response of this interaction.
RAISES | DESCRIPTION |
---|---|
UnauthorizedError | If you are unauthorized to make the request (invalid/missing token). |
NotFoundError | If the interaction or response is not found. |
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. |
delete_message async
#
delete_message(message: SnowflakeishOr[Message]) -> None
Delete a given message in a given channel.
PARAMETER | DESCRIPTION |
---|---|
message | The message to delete. This may be the object or the ID of an existing message. TYPE: |
RAISES | DESCRIPTION |
---|---|
ValueError | If |
UnauthorizedError | If you are unauthorized to make the request (invalid/missing token). |
NotFoundError | If the webhook or the message are not found. |
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. |
edit_initial_response async
#
edit_initial_response(
content: UndefinedNoneOr[Any] = undefined.UNDEFINED,
*,
attachment: UndefinedNoneOr[
Union[Resourceish, Attachment]
] = undefined.UNDEFINED,
attachments: UndefinedNoneOr[
Sequence[Union[Resourceish, Attachment]]
] = undefined.UNDEFINED,
component: UndefinedNoneOr[ComponentBuilder] = undefined.UNDEFINED,
components: UndefinedNoneOr[
Sequence[ComponentBuilder]
] = undefined.UNDEFINED,
embed: UndefinedNoneOr[Embed] = undefined.UNDEFINED,
embeds: UndefinedNoneOr[Sequence[Embed]] = undefined.UNDEFINED,
mentions_everyone: UndefinedOr[bool] = undefined.UNDEFINED,
user_mentions: UndefinedOr[
Union[SnowflakeishSequence[PartialUser], bool]
] = undefined.UNDEFINED,
role_mentions: UndefinedOr[
Union[SnowflakeishSequence[PartialRole], bool]
] = undefined.UNDEFINED
) -> Message
Edit the initial response of this command interaction.
Note
Mentioning everyone, roles, or users in message edits currently will not send a push notification showing a new mention to people on Discord. It will still highlight in their chat as if they were mentioned, however.
Warning
If you specify a text content
, mentions_everyone
, mentions_reply
, user_mentions
, and role_mentions
will default to False
as the message will be re-parsed for mentions. This will also occur if only one of the four are specified
This is a limitation of Discord's design. If in doubt, specify all four of them each time.
PARAMETER | DESCRIPTION |
---|---|
content | If provided, the message contents. If If this is a Likewise, if this is a TYPE: |
attachment | If provided, the attachment to set on the message. If TYPE: |
attachments | If provided, the attachments to set on the message. If TYPE: |
component | If provided, builder object of the component to set for this message. This component will replace any previously set components and passing TYPE: |
components | If provided, a sequence of the component builder objects set for this message. These components will replace any previously set components and passing TYPE: |
embed | If provided, the embed to set on the message. If TYPE: |
embeds | If provided, the embeds to set on the message. If TYPE: |
mentions_everyone | If provided, whether the message should parse @everyone/@here mentions. TYPE: |
user_mentions | If provided, and TYPE: |
role_mentions | If provided, and TYPE: |
RETURNS | DESCRIPTION |
---|---|
Message | The edited message. |
RAISES | DESCRIPTION |
---|---|
ValueError | If more than 100 unique objects/entities are passed for |
TypeError | If both |
BadRequestError | This may be raised in several discrete situations, such as messages being empty with no attachments or embeds; messages with more than 2000 characters in them, embeds that exceed one of the many embed limits; too many attachments; attachments that are too large; invalid image URLs in embeds; too many components. |
UnauthorizedError | If you are unauthorized to make the request (invalid/missing token). |
NotFoundError | If the interaction or the message are not found. |
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. |
edit_message async
#
edit_message(
message: SnowflakeishOr[Message],
content: UndefinedNoneOr[Any] = undefined.UNDEFINED,
*,
attachment: UndefinedNoneOr[
Union[Resourceish, Attachment]
] = undefined.UNDEFINED,
attachments: UndefinedNoneOr[
Sequence[Union[Resourceish, Attachment]]
] = undefined.UNDEFINED,
component: UndefinedNoneOr[ComponentBuilder] = undefined.UNDEFINED,
components: UndefinedNoneOr[
Sequence[ComponentBuilder]
] = undefined.UNDEFINED,
embed: UndefinedNoneOr[Embed] = undefined.UNDEFINED,
embeds: UndefinedNoneOr[Sequence[Embed]] = undefined.UNDEFINED,
mentions_everyone: UndefinedOr[bool] = undefined.UNDEFINED,
user_mentions: UndefinedOr[
Union[SnowflakeishSequence[PartialUser], bool]
] = undefined.UNDEFINED,
role_mentions: UndefinedOr[
Union[SnowflakeishSequence[PartialRole], bool]
] = undefined.UNDEFINED
) -> Message
Edit a message sent by a webhook.
Note
Mentioning everyone, roles, or users in message edits currently will not send a push notification showing a new mention to people on Discord. It will still highlight in their chat as if they were mentioned, however.
Warning
If you specify a text content
, mentions_everyone
, mentions_reply
, user_mentions
, and role_mentions
will default to False
as the message will be re-parsed for mentions. This will also occur if only one of the four are specified
This is a limitation of Discord's design. If in doubt, specify all four of them each time.
PARAMETER | DESCRIPTION |
---|---|
message | The message to delete. This may be the object or the ID of an existing message. TYPE: |
content | If provided, the message contents. If If this is a Likewise, if this is a TYPE: |
attachment | If provided, the attachment to set on the message. If TYPE: |
attachments | If provided, the attachments to set on the message. If TYPE: |
component | If provided, builder object of the component to set for this message. This component will replace any previously set components and passing TYPE: |
components | If provided, a sequence of the component builder objects set for this message. These components will replace any previously set components and passing TYPE: |
embed | If provided, the embed to set on the message. If TYPE: |
embeds | If provided, the embeds to set on the message. If TYPE: |
mentions_everyone | If provided, sanitation for TYPE: |
user_mentions | If provided, and TYPE: |
role_mentions | If provided, and TYPE: |
RETURNS | DESCRIPTION |
---|---|
Message | The edited message. |
RAISES | DESCRIPTION |
---|---|
ValueError | If more than 100 unique objects/entities are passed for |
TypeError | If both |
BadRequestError | This may be raised in several discrete situations, such as messages being empty with no attachments or embeds; messages with more than 2000 characters in them, embeds that exceed one of the many embed limits; too many attachments; attachments that are too large; too many components. |
UnauthorizedError | If you are unauthorized to make the request (invalid/missing token). |
NotFoundError | If the webhook or the message are not found. |
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. |
execute async
#
execute(
content: UndefinedOr[Any] = undefined.UNDEFINED,
*,
username: UndefinedOr[str] = undefined.UNDEFINED,
avatar_url: Union[UndefinedType, str, URL] = undefined.UNDEFINED,
tts: UndefinedOr[bool] = undefined.UNDEFINED,
attachment: UndefinedOr[Resourceish] = undefined.UNDEFINED,
attachments: UndefinedOr[Sequence[Resourceish]] = undefined.UNDEFINED,
component: UndefinedOr[ComponentBuilder] = undefined.UNDEFINED,
components: UndefinedOr[Sequence[ComponentBuilder]] = undefined.UNDEFINED,
embed: UndefinedOr[Embed] = undefined.UNDEFINED,
embeds: UndefinedOr[Sequence[Embed]] = undefined.UNDEFINED,
mentions_everyone: UndefinedOr[bool] = undefined.UNDEFINED,
user_mentions: UndefinedOr[
Union[SnowflakeishSequence[PartialUser], bool]
] = undefined.UNDEFINED,
role_mentions: UndefinedOr[
Union[SnowflakeishSequence[PartialRole], bool]
] = undefined.UNDEFINED,
flags: Union[UndefinedType, int, MessageFlag] = undefined.UNDEFINED
) -> Message
Execute the webhook to create a message.
Warning
At the time of writing, username
and avatar_url
are ignored for interaction webhooks.
Additionally, hikari.messages.MessageFlag.SUPPRESS_EMBEDS
, hikari.messages.MessageFlag.SUPPRESS_NOTIFICATIONS
and hikari.messages.MessageFlag.EPHEMERAL
are the only flags that can be set, with hikari.messages.MessageFlag.EPHEMERAL
being limited to interaction webhooks.
PARAMETER | DESCRIPTION |
---|---|
content | If provided, the message contents. If If this is a Likewise, if this is a TYPE: |
username | If provided, the username to override the webhook's username for this request. TYPE: |
avatar_url | If provided, the url of an image to override the webhook's avatar with for this request. TYPE: |
tts | If provided, whether the message will be sent as a TTS message. TYPE: |
attachment | If provided, the message attachment. This can be a resource, or string of a path on your computer or a URL. TYPE: |
attachments | If provided, the message attachments. These can be resources, or strings consisting of paths on your computer or URLs. TYPE: |
component | If provided, builder object of the component to include in this message. TYPE: |
components | If provided, a sequence of the component builder objects to include in this message. TYPE: |
embed | If provided, the message embed. TYPE: |
embeds | If provided, the message embeds. TYPE: |
mentions_everyone | If provided, whether the message should parse @everyone/@here mentions. TYPE: |
user_mentions | If provided, and TYPE: |
role_mentions | If provided, and TYPE: |
flags | The flags to set for this webhook message. TYPE: |
RETURNS | DESCRIPTION |
---|---|
Message | The created message object. |
RAISES | DESCRIPTION |
---|---|
NotFoundError | If the current webhook is not found. |
BadRequestError | This can be raised if the file is too large; if the embed exceeds the defined limits; if the message content is specified only and empty or greater than |
UnauthorizedError | If you pass a token that's invalid for the target webhook. |
ValueError | If |
TypeError | If both |
fetch_channel async
#
fetch_channel() -> TextableChannel
Fetch the channel this interaction occurred in.
RETURNS | DESCRIPTION |
---|---|
TextableChannel | The channel. This will be a derivative of |
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_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. |
fetch_initial_response async
#
fetch_initial_response() -> Message
Fetch the initial response of this interaction.
RETURNS | DESCRIPTION |
---|---|
Message | Message object of the initial response. |
RAISES | DESCRIPTION |
---|---|
ForbiddenError | If you cannot access the target interaction. |
NotFoundError | If the initial response 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_message async
#
fetch_message(message: SnowflakeishOr[Message]) -> Message
Fetch an old message sent by the webhook.
PARAMETER | DESCRIPTION |
---|---|
message | The message to fetch. This may be the object or the ID of an existing channel. TYPE: |
RETURNS | DESCRIPTION |
---|---|
Message | The requested message. |
RAISES | DESCRIPTION |
---|---|
ValueError | If |
UnauthorizedError | If you are unauthorized to make the request (invalid/missing token). |
NotFoundError | If the webhook is not found or the webhook's message wasn't found. |
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() -> Union[GuildTextChannel, GuildNewsChannel, None]
Get the guild channel this interaction occurred in.
Note
This will always return None
for interactions triggered in a DM channel.
RETURNS | DESCRIPTION |
---|---|
Union[GuildTextChannel, GuildNewsChannel, None] | 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 from the cache.
RETURNS | DESCRIPTION |
---|---|
Optional[GatewayGuild] | The object of the guild if found, else |