hikari.interactions.base_interactions#

Base classes and enums inherited and used throughout the interactions flow.

Module Contents#

class hikari.interactions.base_interactions.InteractionChannel[source]#

Bases: hikari.channels.PartialChannel

Represents partial channels returned as resolved entities on interactions.

permissions: hikari.permissions.Permissions[source]#

Permissions the command’s executor has in this channel.

class hikari.interactions.base_interactions.InteractionMember[source]#

Bases: hikari.guilds.Member

Model of the member who triggered an interaction.

Unlike hikari.guilds.Member, this object comes with an extra InteractionMember.permissions field.

permissions: hikari.permissions.Permissions[source]#

Permissions the member has in the current channel.

class hikari.interactions.base_interactions.InteractionType[source]#

Bases: int, hikari.internal.enums.Enum

The type of an interaction.

APPLICATION_COMMAND = 2[source]#

An interaction triggered by a user calling an application command.

AUTOCOMPLETE = 4[source]#

An interaction triggered by a user typing in a slash command option.

MESSAGE_COMPONENT = 3[source]#

An interaction triggered by a user calling a message component.

MODAL_SUBMIT = 5[source]#

An interaction triggered by a user submitting a modal.

class hikari.interactions.base_interactions.MessageResponseMixin[source]#

Bases: PartialInteraction, Generic[_CommandResponseTypesT]

Mixin’ class for all interaction types which can be responded to with a message.

async create_initial_response(response_type, content=undefined.UNDEFINED, *, flags=undefined.UNDEFINED, tts=undefined.UNDEFINED, attachment=undefined.UNDEFINED, attachments=undefined.UNDEFINED, component=undefined.UNDEFINED, components=undefined.UNDEFINED, embed=undefined.UNDEFINED, embeds=undefined.UNDEFINED, mentions_everyone=undefined.UNDEFINED, user_mentions=undefined.UNDEFINED, role_mentions=undefined.UNDEFINED)[source]#

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.

Parameters:
response_typetyping.Union[int, CommandResponseTypesT]

The type of interaction response this is.

Other Parameters:
contenthikari.undefined.UndefinedOr[typing.Any]

If provided, the message contents. If hikari.undefined.UNDEFINED, then nothing will be sent in the content. Any other value here will be cast to a str.

If this is a hikari.embeds.Embed and no embed nor embeds kwarg is provided, then this will instead update the embed. This allows for simpler syntax when sending an embed alone.

attachmenthikari.undefined.UndefinedNoneOr[typing.Union[hikari.files.Resourceish, hikari.messages.Attachment]]

If provided, the message attachment. This can be a resource, or string of a path on your computer or a URL.

attachmentshikari.undefined.UndefinedNoneOr[typing.Sequence[typing.Union[hikari.files.Resourceish, hikari.messages.Attachment]]]

If provided, the message attachments. These can be resources, or strings consisting of paths on your computer or URLs.

componenthikari.undefined.UndefinedNoneOr[hikari.api.special_endpoints.ComponentBuilder]

If provided, builder object of the component to include in this message.

componentshikari.undefined.UndefinedNoneOr[typing.Sequence[hikari.api.special_endpoints.ComponentBuilder]]

If provided, a sequence of the component builder objects to include in this message.

embedhikari.undefined.UndefinedNoneOr[hikari.embeds.Embed]

If provided, the message embed.

embedshikari.undefined.UndefinedNoneOr[typing.Sequence[hikari.embeds.Embed]]

If provided, the message embeds.

flagstyping.Union[int, hikari.messages.MessageFlag, hikari.undefined.UndefinedType]

If provided, the message flags this response should have.

As of writing the only message flags which can be set here are hikari.messages.MessageFlag.EPHEMERAL, hikari.messages.MessageFlag.SUPPRESS_NOTIFICATIONS and hikari.messages.MessageFlag.SUPPRESS_EMBEDS.

ttshikari.undefined.UndefinedOr[bool]

If provided, whether the message will be read out by a screen reader using Discord’s TTS (text-to-speech) system.

mentions_everyonehikari.undefined.UndefinedOr[bool]

If provided, whether the message should parse @everyone/@here mentions.

user_mentionshikari.undefined.UndefinedOr[typing.Union[hikari.snowflakes.SnowflakeishSequence[hikari.users.PartialUser], bool]]

If provided, and True, all user mentions will be detected. If provided, and False, all user mentions will be ignored if appearing in the message body. Alternatively this may be a collection of hikari.snowflakes.Snowflake, or hikari.users.PartialUser derivatives to enforce mentioning specific users.

role_mentionshikari.undefined.UndefinedOr[typing.Union[hikari.snowflakes.SnowflakeishSequence[hikari.guilds.PartialRole], bool]]

If provided, and True, all role mentions will be detected. If provided, and False, all role mentions will be ignored if appearing in the message body. Alternatively this may be a collection of hikari.snowflakes.Snowflake, or hikari.guilds.PartialRole derivatives to enforce mentioning specific roles.

Raises:
ValueError

If more than 100 unique objects/entities are passed for role_mentions or user_mentions.

TypeError

If both embed and embeds are specified.

hikari.errors.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.

hikari.errors.UnauthorizedError

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

hikari.errors.NotFoundError

If the interaction is not found or if the interaction’s initial response has already been created.

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 delete_initial_response()[source]#

Delete the initial response of this interaction.

Raises:
hikari.errors.UnauthorizedError

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

hikari.errors.NotFoundError

If the interaction or response 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.InternalServerError

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

async edit_initial_response(content=undefined.UNDEFINED, *, attachment=undefined.UNDEFINED, attachments=undefined.UNDEFINED, component=undefined.UNDEFINED, components=undefined.UNDEFINED, embed=undefined.UNDEFINED, embeds=undefined.UNDEFINED, mentions_everyone=undefined.UNDEFINED, user_mentions=undefined.UNDEFINED, role_mentions=undefined.UNDEFINED)[source]#

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.

Other Parameters:
contenthikari.undefined.UndefinedNoneOr[typing.Any]

If provided, the message contents. If hikari.undefined.UNDEFINED, then nothing will be sent in the content. Any other value here will be cast to a str.

If this is a hikari.embeds.Embed and neither the embed or embeds kwargs are provided or if this is a hikari.files.Resourceish and neither the attachment or attachments kwargs are provided, the values will be overwritten. This allows for simpler syntax when sending an embed or an attachment alone.

Likewise, if this is a hikari.files.Resource, then the content is instead treated as an attachment if no attachment and no attachments kwargs are provided.

attachmenthikari.undefined.UndefinedNoneOr[typing.Union[hikari.files.Resourceish, hikari.messages.Attachment]]

If provided, the attachment to set on the message. If hikari.undefined.UNDEFINED, the previous attachment, if present, is not changed. If this is None, then the attachment is removed, if present. Otherwise, the new attachment that was provided will be attached.

attachmentshikari.undefined.UndefinedNoneOr[typing.Sequence[typing.Union[hikari.files.Resourceish, hikari.messages.Attachment]]]

If provided, the attachments to set on the message. If hikari.undefined.UNDEFINED, the previous attachments, if present, are not changed. If this is None, then the attachments is removed, if present. Otherwise, the new attachments that were provided will be attached.

componenthikari.undefined.UndefinedNoneOr[hikari.api.special_endpoints.ComponentBuilder]

If provided, builder object of the component to set for this message. This component will replace any previously set components and passing None will remove all components.

componentshikari.undefined.UndefinedNoneOr[typing.Sequence[hikari.api.special_endpoints.ComponentBuilder]]

If provided, a sequence of the component builder objects set for this message. These components will replace any previously set components and passing None or an empty sequence will remove all components.

embedhikari.undefined.UndefinedNoneOr[hikari.embeds.Embed]

If provided, the embed to set on the message. If hikari.undefined.UNDEFINED, the previous embed(s) are not changed. If this is None then any present embeds are removed. Otherwise, the new embed that was provided will be used as the replacement.

embedshikari.undefined.UndefinedNoneOr[typing.Sequence[hikari.embeds.Embed]]

If provided, the embeds to set on the message. If hikari.undefined.UNDEFINED, the previous embed(s) are not changed. If this is None then any present embeds are removed. Otherwise, the new embeds that were provided will be used as the replacement.

mentions_everyonehikari.undefined.UndefinedOr[bool]

If provided, whether the message should parse @everyone/@here mentions.

user_mentionshikari.undefined.UndefinedOr[typing.Union[hikari.snowflakes.SnowflakeishSequence[hikari.users.PartialUser], bool]]

If provided, and True, all user mentions will be detected. If provided, and False, all user mentions will be ignored if appearing in the message body. Alternatively this may be a collection of hikari.snowflakes.Snowflake, or hikari.users.PartialUser derivatives to enforce mentioning specific users.

role_mentionshikari.undefined.UndefinedOr[typing.Union[hikari.snowflakes.SnowflakeishSequence[hikari.guilds.PartialRole], bool]]

If provided, and True, all role mentions will be detected. If provided, and False, all role mentions will be ignored if appearing in the message body. Alternatively this may be a collection of hikari.snowflakes.Snowflake, or hikari.guilds.PartialRole derivatives to enforce mentioning specific roles.

Returns:
hikari.messages.Message

The edited message.

Raises:
ValueError

If more than 100 unique objects/entities are passed for role_mentions or user_mentions.

TypeError

If both embed and embeds are specified.

hikari.errors.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.

hikari.errors.UnauthorizedError

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

hikari.errors.NotFoundError

If the interaction or the message are 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.InternalServerError

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

async fetch_initial_response()[source]#

Fetch the initial response of this interaction.

Returns:
hikari.messages.Message

Message object of the initial response.

Raises:
hikari.errors.ForbiddenError

If you cannot access the target interaction.

hikari.errors.NotFoundError

If the initial response isn’t 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.

class hikari.interactions.base_interactions.ModalResponseMixin[source]#

Bases: PartialInteraction

Mixin’ class for all interaction types which can be responded to with a modal.

build_modal_response(title, custom_id)[source]#

Create a builder for a modal interaction response.

Parameters:
titlestr

The title that will show up in the modal.

custom_idstr

Developer set custom ID used for identifying interactions with this modal.

Returns:
hikari.api.special_endpoints.InteractionModalBuilder

The interaction modal response builder object.

async create_modal_response(title, custom_id, component=undefined.UNDEFINED, components=undefined.UNDEFINED)[source]#

Create a response by sending a modal.

Parameters:
titlestr

The title that will show up in the modal.

custom_idstr

Developer set custom ID used for identifying interactions with this modal.

Other Parameters:
componenthikari.undefined.UndefinedOr[typing.Sequence[hikari.api.special_endpoints.ComponentBuilder]]

A component builder to send in this modal.

componentshikari.undefined.UndefinedOr[typing.Sequence[hikari.api.special_endpoints.ComponentBuilder]]

A sequence of component builders to send in this modal.

Raises:
ValueError

If both component and components are specified or if none are specified.

class hikari.interactions.base_interactions.PartialInteraction[source]#

Bases: hikari.snowflakes.Unique, hikari.webhooks.ExecutableWebhook

The base model for all interaction models.

app: hikari.traits.RESTAware[source]#

Client application that models may use for procedures.

application_id: hikari.snowflakes.Snowflake[source]#

ID of the application this interaction belongs to.

token: str[source]#

The interaction’s token.

type: InteractionType | int[source]#

The type of interaction this is.

version: int[source]#

Version of the interaction system this interaction is under.

class hikari.interactions.base_interactions.ResolvedOptionData[source]#

Represents the resolved objects of entities referenced in a command’s options.

attachments: Mapping[hikari.snowflakes.Snowflake, messages.Attachment][source]#

Mapping of snowflake IDs to the attachment objects.

channels: Mapping[hikari.snowflakes.Snowflake, InteractionChannel][source]#

Mapping of snowflake IDs to the resolved option partial channel objects.

members: Mapping[hikari.snowflakes.Snowflake, InteractionMember][source]#

Mapping of snowflake IDs to the resolved option member objects.

messages: Mapping[hikari.snowflakes.Snowflake, messages.Message][source]#

Mapping of snowflake IDs to the resolved option partial message objects.

roles: Mapping[hikari.snowflakes.Snowflake, hikari.guilds.Role][source]#

Mapping of snowflake IDs to the resolved option role objects.

users: Mapping[hikari.snowflakes.Snowflake, users.User][source]#

Mapping of snowflake IDs to the resolved option user objects.

class hikari.interactions.base_interactions.ResponseType[source]#

Bases: int, hikari.internal.enums.Enum

The type of an interaction response.

AUTOCOMPLETE = 8[source]#

Respond to an autocomplete interaction with suggested choices.

This is valid for the following interaction types:

DEFERRED_MESSAGE_CREATE = 5[source]#

Acknowledge an interaction with the intention to edit in a message response later.

The user will see a loading state when this type is used until this interaction expires or a message response is edited in over REST.

This is valid for the following interaction types:

DEFERRED_MESSAGE_UPDATE = 6[source]#

Acknowledge an interaction with the intention to edit its message later.

This is valid for the following interaction types:

MESSAGE_CREATE = 4[source]#

An immediate message response to an interaction.

MESSAGE_UPDATE = 7[source]#

An immediate interaction response with instructions on how to update its message.

This is valid for the following interaction types:

MODAL = 9[source]#

An immediate interaction response with instructions to display a modal.

This is valid for the following interaction types:

hikari.interactions.base_interactions.DEFERRED_RESPONSE_TYPES: Final[AbstractSet[DeferredResponseTypesT]][source]#

Set of the response types which are valid for deferred messages responses.

This includes the following:

hikari.interactions.base_interactions.DeferredResponseTypesT[source]#

Type-hint of the response types which are valid for deferred messages responses.

The following are valid for this:

hikari.interactions.base_interactions.MESSAGE_RESPONSE_TYPES: Final[AbstractSet[MessageResponseTypesT]][source]#

Set of the response types which are valid for message responses.

This includes the following:

hikari.interactions.base_interactions.MessageResponseTypesT[source]#

Type-hint of the response types which are valid for message responses.

The following are valid for this: