hikari.interactions.modal_interactions#

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

Module Contents#

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:

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

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

Represents a modal interaction on Discord.

channel_id: hikari.snowflakes.Snowflake[source]#

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

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

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.

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

The member who triggered this modal interaction.

This will be builtins.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.

user: hikari.users.User[source]#

The user who triggered this modal interaction.

locale: str[source]#

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

app_permissions: Optional[hikari.permissions.Permissions][source]#

Permissions the bot has in this interaction’s channel if it’s in a guild.

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

Components in the modal.

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.

get_channel()[source]#

Get the guild channel this interaction was triggered in from the cache.

Note

This will always return builtins.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 builtins.None.

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

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

```py async def handle_modal_interaction(interaction: ModalInteraction) -> InteractionMessageBuilder:

return (

interaction .build_response() .add_embed(Embed(description=”Hi there”)) .set_content(“Konnichiwa”)

)

```

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.