hikari.interactions.component_interactions#

Models and enums used for Discord’s Components interaction flow.

Module Contents#

class hikari.interactions.component_interactions.ComponentInteraction[source]#

Bases: hikari.interactions.base_interactions.MessageResponseMixin[ComponentResponseTypesT], hikari.interactions.base_interactions.ModalResponseMixin

Represents a component 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.

channel_id: hikari.snowflakes.Snowflake[source]#

ID of the channel this interaction was triggered in.

component_type: hikari.components.ComponentType | int[source]#

The type of component which triggers this interaction.

Note

This will never be ButtonStyle.LINK as link buttons don’t trigger interactions.

custom_id: str[source]#

Developer defined ID of the component which triggered this interaction.

guild_id: hikari.snowflakes.Snowflake | None[source]#

ID of the guild this interaction was triggered in.

This will be None for component interactions triggered in DMs.

guild_locale: str | hikari.locales.Locale | None[source]#

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.

locale: str | hikari.locales.Locale[source]#

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

member: hikari.interactions.base_interactions.InteractionMember | None[source]#

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: hikari.messages.Message[source]#

Object of the message the components for this interaction are attached to.

resolved: hikari.interactions.base_interactions.ResolvedOptionData | None[source]#

Mappings of the objects resolved for the provided command options.

user: hikari.users.User[source]#

The user who triggered this interaction.

values: Sequence[str][source]#

Sequence of the values which were selected for a select menu component.

build_deferred_response(type_, /)[source]#

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

Note

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

Parameters:
type_typing.Union[int, hikari.interactions.base_interactions.ResponseType]

The type of deferred response this should be.

This may be one of the following:

Returns:
hikari.api.special_endpoints.InteractionDeferredBuilder

Deferred interaction message response builder object.

build_response(type_, /)[source]#

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

Note

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

Parameters:
type_typing.Union[int, hikari.interactions.base_interactions.ResponseType]

The type of immediate response this should be.

This may be one of the following:

Returns:
hikari.api.special_endpoints.InteractionMessageBuilder

Interaction message response builder object.

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")
    )
async fetch_channel()[source]#

Fetch the channel this interaction occurred in.

Returns:
hikari.channels.TextableChannel

The channel. This will be a _derivative_ of hikari.channels.TextableChannel.

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_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 interaction occurred in.

Note

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

Returns:
typing.Union[hikari.channels.GuildTextChannel, hikari.channels.GuildNewsChannel, None]

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 from the cache.

Returns:
typing.Optional[hikari.guilds.GatewayGuild]

The object of the guild if found, else None.

hikari.interactions.component_interactions.COMPONENT_RESPONSE_TYPES: Final[AbstractSet[ComponentResponseTypesT]][source]#

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

This includes:

hikari.interactions.component_interactions.ComponentResponseTypesT[source]#

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

The following types are valid for this: