Skip to content

yuyo.interactions#

Base classes used for interaction handling.

BaseContext #

Bases: ABC, Generic[_InteractionT]

Base class for components contexts.

alluka abstractmethod property #

alluka

The Alluka client being used for callback dependency injection.

author property #

author

Author of this interaction.

cache abstractmethod property #

cache

Hikari cache instance this context's client was initialised with.

channel_id property #

channel_id

ID of the channel this interaction was triggered in.

events abstractmethod property #

events

Object of the event manager this context's client was initialised with.

expires_at property #

expires_at

When this context expires.

After this time is reached, the message/response methods on this context will always raise hikari.NotFoundError.

has_been_deferred property #

has_been_deferred

Whether this context's initial response has been deferred.

This will be true if BaseContext.defer has been called.

has_responded property #

has_responded

Whether an initial response has been made to this context yet.

It's worth noting that a context must be either responded to or deferred within 3 seconds from it being received otherwise it'll be marked as failed.

This will be true if either BaseContext.respond, BaseContext.create_initial_response or BaseContext.edit_initial_response (after a deferral) has been called.

id_match property #

id_match

Section of the ID used to identify the relevant executor.

id_metadata property #

id_metadata

Metadata from the interaction's custom ID.

interaction property #

interaction

Object of the interaction this context is for.

rest abstractmethod property #

rest

Object of the Hikari REST client this context's client was initialised with.

server abstractmethod property #

server

Object of the Hikari interaction server provided for this context's client.

shard property #

shard

Shard that triggered the interaction.

Note

This will be None if BaseContext.shards is also None.

shards abstractmethod property #

shards

Object of the Hikari shard manager this context's client was initialised with.

voice abstractmethod property #

voice

Object of the Hikari voice component this context's client was initialised with.

__init__ #

__init__(interaction, id_match, id_metadata, register_task, *, ephemeral_default=False, response_future=None)

Initialise a base context.

create_followup async #

create_followup(content=hikari.UNDEFINED, *, delete_after=None, ephemeral=None, attachment=hikari.UNDEFINED, attachments=hikari.UNDEFINED, component=hikari.UNDEFINED, components=hikari.UNDEFINED, embed=hikari.UNDEFINED, embeds=hikari.UNDEFINED, mentions_everyone=hikari.UNDEFINED, user_mentions=hikari.UNDEFINED, role_mentions=hikari.UNDEFINED, tts=hikari.UNDEFINED, flags=hikari.UNDEFINED)

Create a followup response for this context.

Warning

Calling this on a context which hasn't had an initial response yet will lead to a hikari.NotFoundError being raised.

Parameters:

Returns:

  • Message

    The created message object.

Raises:

  • NotFoundError

    If the current interaction is not found or it hasn't had an initial response yet.

  • BadRequestError

    This can be raised if the file is too large; if the embed exceeds the defined limits; if the message content is specified only and empty or greater than 2000 characters; if neither content, file or embeds are specified. If any invalid snowflake IDs are passed; a snowflake may be invalid due to it being outside of the range of a 64 bit integer.

  • ValueError

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

    If the interaction will have expired before delete_after is reached.

    If both attachment and attachments are passed or both component and components are passed or both embed and embeds are passed.

create_initial_response async #

create_initial_response(content=hikari.UNDEFINED, *, response_type=hikari.ResponseType.MESSAGE_CREATE, delete_after=None, ephemeral=None, attachment=hikari.UNDEFINED, attachments=hikari.UNDEFINED, component=hikari.UNDEFINED, components=hikari.UNDEFINED, embed=hikari.UNDEFINED, embeds=hikari.UNDEFINED, mentions_everyone=hikari.UNDEFINED, user_mentions=hikari.UNDEFINED, role_mentions=hikari.UNDEFINED, flags=hikari.UNDEFINED, tts=hikari.UNDEFINED)

Create the initial response for this context.

Warning

Calling this on a context which already has an initial response will result in this raising a hikari.NotFoundError. This includes if the REST interaction server has already responded to the request and deferrals.

Parameters:

Raises:

  • ValueError

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

    If the interaction will have expired before delete_after is reached.

    If both attachment and attachments are passed or both component and components are passed or both embed and embeds are passed.

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

  • UnauthorizedError

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

  • NotFoundError

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

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

defer async #

defer(*, defer_type=hikari.ResponseType.DEFERRED_MESSAGE_CREATE, ephemeral=None, flags=hikari.UNDEFINED)

Defer the initial response for this context.

Note

The ephemeral state of the first response is decided by whether the deferral is ephemeral.

Parameters:

delete_initial_response async #

delete_initial_response()

Delete the initial response after invoking this context.

Raises:

delete_last_response async #

delete_last_response()

Delete the last response after invoking this context.

Raises:

edit_initial_response async #

edit_initial_response(content=hikari.UNDEFINED, *, delete_after=None, attachment=hikari.UNDEFINED, attachments=hikari.UNDEFINED, component=hikari.UNDEFINED, components=hikari.UNDEFINED, embed=hikari.UNDEFINED, embeds=hikari.UNDEFINED, mentions_everyone=hikari.UNDEFINED, user_mentions=hikari.UNDEFINED, role_mentions=hikari.UNDEFINED)

Edit the initial response for this context.

Parameters:

Returns:

  • Message

    The message that has been edited.

Raises:

  • ValueError

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

    If delete_after would be more than 15 minutes after the interaction was received.

    If both attachment and attachments are passed or both component and components are passed or both embed and embeds are passed.

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

  • UnauthorizedError

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

  • ForbiddenError

    If you are missing the SEND_MESSAGES in the channel or the person you are trying to message has the DM's disabled.

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

  • InternalServerError

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

edit_last_response async #

edit_last_response(content=hikari.UNDEFINED, *, delete_after=None, attachment=hikari.UNDEFINED, attachments=hikari.UNDEFINED, component=hikari.UNDEFINED, components=hikari.UNDEFINED, embed=hikari.UNDEFINED, embeds=hikari.UNDEFINED, mentions_everyone=hikari.UNDEFINED, user_mentions=hikari.UNDEFINED, role_mentions=hikari.UNDEFINED)

Edit the last response for this context.

Parameters:

Returns:

  • Message

    The message that has been edited.

Raises:

  • ValueError

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

    If delete_after would be more than 15 minutes after the slash interaction was received.

    If both attachment and attachments are passed or both component and components are passed or both embed and embeds are passed.

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

  • UnauthorizedError

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

  • ForbiddenError

    If you are missing the SEND_MESSAGES in the channel or the person you are trying to message has the DM's disabled.

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

  • InternalServerError

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

fetch_initial_response async #

fetch_initial_response()

Fetch the initial response for this context.

Returns:

  • Message

    The initial response's message object.

Raises:

fetch_last_response async #

fetch_last_response()

Fetch the last response for this context.

Returns:

  • Message

    The most response response's message object.

Raises:

respond async #

respond(content=hikari.UNDEFINED, *, ensure_result=False, delete_after=None, attachment=hikari.UNDEFINED, attachments=hikari.UNDEFINED, component=hikari.UNDEFINED, components=hikari.UNDEFINED, embed=hikari.UNDEFINED, embeds=hikari.UNDEFINED, mentions_everyone=hikari.UNDEFINED, user_mentions=hikari.UNDEFINED, role_mentions=hikari.UNDEFINED)

Respond to this context.

Parameters:

Returns:

  • Message | None

    The message that has been created if it was immedieatly available or ensure_result was set to True, else None.

Raises:

  • ValueError

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

    If delete_after would be more than 15 minutes after the interaction was received.

    If both attachment and attachments are passed or both component and components are passed or both embed and embeds are passed.

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

  • UnauthorizedError

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

  • ForbiddenError

    If you are missing the SEND_MESSAGES in the channel or the person you are trying to message has the DM's disabled.

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

  • InternalServerError

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

set_ephemeral_default #

set_ephemeral_default(state)

Set the ephemeral default state for this context.

Parameters:

  • state (bool) –

    The new ephemeral default state.

    If this is True then all calls to the response creating methods on this context will default to being ephemeral.

InteractionError #

Bases: Exception

Error which is sent as a response to a modal or component call.

__init__ #

__init__(content=hikari.UNDEFINED, *, delete_after=None, attachment=hikari.UNDEFINED, attachments=hikari.UNDEFINED, component=hikari.UNDEFINED, components=hikari.UNDEFINED, embed=hikari.UNDEFINED, embeds=hikari.UNDEFINED, mentions_everyone=hikari.UNDEFINED, user_mentions=hikari.UNDEFINED, role_mentions=hikari.UNDEFINED)

Initialise an interaction error.

Parameters:

Raises:

  • ValueError

    Raised for any of the following reasons:

    • When both attachment and attachments are provided.
    • When both component and components are passed.
    • When both embed and embeds are passed.
    • If more than 100 entries are passed for role_mentions.
    • If more than 100 entries are passed for user_mentions.

send async #

send(ctx, /, *, ensure_result=False)

Send this error as an interaction response.

Parameters:

Raises:

  • ValueError

    If delete_after would be more than 15 minutes after the interaction was received.

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

  • UnauthorizedError

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

  • ForbiddenError

    If you are missing the SEND_MESSAGES in the channel or the person you are trying to message has the DM's disabled.

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

  • InternalServerError

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