Skip to content

hikari.interactions.component_interactions#

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

ComponentResponseTypesT module-attribute #

ComponentResponseTypesT = Union[_ImmediateTypesT, _DeferredTypesT]

ComponentInteraction #

Bases: MessageResponseMixin[ComponentResponseTypesT], ModalResponseMixin, PremiumResponseMixin

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

channel_id class-attribute instance-attribute #

channel_id: Snowflake = field(eq=False)

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 #

custom_id: str = field(eq=False)

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 #

guild_id: Optional[Snowflake] = field(eq=False)

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 #

guild_locale: Optional[Union[str, Locale]] = field(eq=False, hash=False, repr=True)

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 class-attribute instance-attribute #

locale: Union[str, Locale] = field(eq=False, hash=False, repr=True)

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 #

message: Message = field(eq=False, repr=False)

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.

user class-attribute instance-attribute #

user: User = field(eq=False, hash=False, repr=True)

The user who triggered this interaction.

values class-attribute instance-attribute #

values: Sequence[str] = field(eq=False)

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

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_

TYPE: _DeferredTypesT

RETURNS DESCRIPTION
InteractionDeferredBuilder

Deferred interaction message 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_

TYPE: _ImmediateTypesT

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.

fetch_channel async #

fetch_channel() -> TextableChannel

Fetch the channel this interaction occurred in.

RETURNS DESCRIPTION
TextableChannel

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

RAISES DESCRIPTION
UnauthorizedError

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

ForbiddenError

If you are missing the hikari.permissions.Permissions.VIEW_CHANNEL permission in the channel.

NotFoundError

If the channel is not found.

RateLimitTooLongError

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

RateLimitTooLongError

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

InternalServerError

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

fetch_guild async #

fetch_guild() -> Optional[RESTGuild]

Fetch the guild this interaction happened in.

RETURNS DESCRIPTION
Optional[RESTGuild]

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

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 max_rate_limit when making a request.

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 None.

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 None.