hikari.interactions.modal_interactions#

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

Module Contents#

class hikari.interactions.modal_interactions.ModalInteraction[source]#

Bases: hikari.interactions.base_interactions.MessageResponseMixin[ModalResponseTypesT]

Represents a modal interaction on Discord.

app_permissions: Optional[hikari.permissions.Permissions][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 modal interaction event was triggered in.

components: Sequence[hikari.components.ModalActionRowComponent][source]#

Components in the modal.

custom_id: str[source]#

The custom id of the modal.

guild_id: Optional[hikari.snowflakes.Snowflake][source]#

ID of the guild this modal interaction event was triggered in.

This will be None for modal interactions triggered in DMs.

guild_locale: Optional[str][source]#

The preferred language of the guild this modal interaction was triggered in.

This will be None for modal 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[source]#

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

member: Optional[hikari.interactions.base_interactions.InteractionMember][source]#

The member who triggered this modal interaction.

This will be None for modal 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: Optional[hikari.messages.Message][source]#

The message whose component triggered the modal.

This will be None if the modal was a response to a command.

user: hikari.users.User[source]#

The user who triggered this modal interaction.

build_deferred_response()[source]#

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

Note

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

Deferred interaction message response builder object.

build_response()[source]#

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

Note

For interactions received over the gateway ModalInteraction.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_modal_interaction(interaction: ModalInteraction) -> InteractionMessageBuilder:
    return (
        interaction
        .build_response()
        .add_embed(Embed(description="Hi there"))
        .set_content("Konnichiwa")
    )
async fetch_channel()[source]#

Fetch the guild channel this interaction was triggered in.

Returns:
hikari.channels.TextableChannel

The requested partial channel derived object of the channel this interaction 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.RateLimitedError

Usually, Hikari will handle and retry on hitting rate-limits automatically. This includes most bucket-specific rate-limits and global rate-limits. In some rare edge cases, however, Discord implements other undocumented rules for rate-limiting, such as limits per attribute. These cannot be detected or handled normally by Hikari due to their undocumented nature, and will trigger this exception if they occur.

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

Usually, Hikari will handle and retry on hitting rate-limits automatically. This includes most bucket-specific rate-limits and global rate-limits. In some rare edge cases, however, Discord implements other undocumented rules for rate-limiting, such as limits per attribute. These cannot be detected or handled normally by Hikari due to their undocumented nature, and will trigger this exception if they occur.

hikari.errors.InternalServerError

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

get_channel()[source]#

Get the guild channel this interaction 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 the guild this interaction was triggered in from the cache.

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

The object of the guild if found, else None.

hikari.interactions.modal_interactions.ModalResponseTypesT[source]#

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

The following types are valid for this: