Skip to content

Context ABC API Reference#

InteractionResponse #

InteractionResponse(
    context: Context[InteractionT],
    message: hikari.Message | None = None,
)

Represents a message response to an interaction, allows for standardized handling of responses. This class is not meant to be directly instantiated, and is instead returned by Context.

delete_after #

delete_after(
    delay: int | float | datetime.timedelta,
) -> None

Delete the response after the specified delay.

PARAMETER DESCRIPTION
delay

The delay after which the response should be deleted.

TYPE: Union[int, float, datetime.timedelta]

retrieve_message async #

retrieve_message() -> hikari.Message

Get or fetch the message created by this response. Initial responses need to be fetched, while followups will be provided directly.

Note

The object itself can also be awaited directly, which in turn calls this method, producing the same results.

RETURNS DESCRIPTION
hikari.Message

The message created by this response.

delete async #

delete() -> None

Delete the response issued to the interaction this object represents.

edit async #

edit(
    content: hikari.UndefinedOr[t.Any] = hikari.UNDEFINED,
    *,
    component: hikari.UndefinedOr[
        hikari.api.ComponentBuilder
    ] = hikari.UNDEFINED,
    components: hikari.UndefinedOr[
        t.Sequence[hikari.api.ComponentBuilder]
    ] = hikari.UNDEFINED,
    attachment: hikari.UndefinedOr[
        hikari.Resourceish
    ] = hikari.UNDEFINED,
    attachments: hikari.UndefinedOr[
        t.Sequence[hikari.Resourceish]
    ] = hikari.UNDEFINED,
    embed: hikari.UndefinedOr[
        hikari.Embed
    ] = hikari.UNDEFINED,
    embeds: hikari.UndefinedOr[
        t.Sequence[hikari.Embed]
    ] = hikari.UNDEFINED,
    mentions_everyone: hikari.UndefinedOr[
        bool
    ] = hikari.UNDEFINED,
    user_mentions: hikari.UndefinedOr[
        hikari.SnowflakeishSequence[hikari.PartialUser]
        | bool
    ] = hikari.UNDEFINED,
    role_mentions: hikari.UndefinedOr[
        hikari.SnowflakeishSequence[hikari.PartialRole]
        | bool
    ] = hikari.UNDEFINED
) -> InteractionResponse

A short-hand method to edit the message belonging to this response.

PARAMETER DESCRIPTION
content

The content of the message. Anything passed here will be cast to str.

TYPE: undefined.UndefinedOr[t.Any] DEFAULT: hikari.UNDEFINED

attachment

An attachment to add to this message.

TYPE: undefined.UndefinedOr[hikari.Resourceish] DEFAULT: hikari.UNDEFINED

attachments

A sequence of attachments to add to this message.

TYPE: undefined.UndefinedOr[t.Sequence[hikari.Resourceish]] DEFAULT: hikari.UNDEFINED

component

A component to add to this message.

TYPE: undefined.UndefinedOr[hikari.api.special_endpoints.ComponentBuilder] DEFAULT: hikari.UNDEFINED

components

A sequence of components to add to this message.

TYPE: undefined.UndefinedOr[t.Sequence[hikari.api.special_endpoints.ComponentBuilder]] DEFAULT: hikari.UNDEFINED

embed

An embed to add to this message.

TYPE: undefined.UndefinedOr[hikari.Embed] DEFAULT: hikari.UNDEFINED

embeds

A sequence of embeds to add to this message.

TYPE: undefined.UndefinedOr[t.Sequence[hikari.Embed]] DEFAULT: hikari.UNDEFINED

mentions_everyone

If True, mentioning @everyone will be allowed.

TYPE: undefined.UndefinedOr[bool] DEFAULT: hikari.UNDEFINED

user_mentions

The set of allowed user mentions in this message. Set to True to allow all.

TYPE: undefined.UndefinedOr[[hikari.SnowflakeishSequence[hikari.PartialUser] | bool] DEFAULT: hikari.UNDEFINED

role_mentions

The set of allowed role mentions in this message. Set to True to allow all.

TYPE: undefined.UndefinedOr[[hikari.SnowflakeishSequence[hikari.PartialRole] | bool] DEFAULT: hikari.UNDEFINED

RETURNS DESCRIPTION
InteractionResponse

A proxy object representing the response to the interaction.

Context #

Context(client: Client, interaction: InteractionT)

Bases: abc.ABC, t.Generic[InteractionT]

An abstract base class for context objects that proxying a Discord interaction.

interaction property #

interaction: InteractionT

The underlying interaction object.

Warning

This should not be used directly in most cases, and is only exposed for advanced use cases.

If you use the interaction to create a response in a view, you should disable the autodefer feature in your View.

custom_id property #

custom_id: str

The developer provided unique identifier for the interaction this context is proxying.

responses property #

A list of all responses issued to the interaction this context is proxying.

client property #

client: Client

The client that loaded miru.

user property #

user: hikari.User

The user who triggered this interaction.

author property #

author: hikari.User

Alias for Context.user.

member property #

member: hikari.InteractionMember | None

The member who triggered this interaction. Will be None in DMs.

locale property #

locale: str | hikari.Locale

The locale of this context.

guild_locale property #

guild_locale: str | hikari.Locale | None

The guild locale of this context, if in a guild. This will default to en-US if not a community guild.

app_permissions property #

app_permissions: hikari.Permissions | None

The permissions of the bot. Will be None in DMs.

channel_id property #

channel_id: hikari.Snowflake

The ID of the channel the context represents.

guild_id property #

guild_id: hikari.Snowflake | None

The ID of the guild the context represents. Will be None in DMs.

is_valid property #

is_valid: bool

Returns if the underlying interaction expired or not. This is not 100% accurate due to API latency, but should be good enough for most use cases.

issued_response property #

issued_response: bool

Whether this interaction was already issued an initial response.

get_guild #

get_guild() -> hikari.GatewayGuild | None

Gets the guild this context represents, if any. Requires application cache.

get_channel #

get_channel() -> hikari.TextableGuildChannel | None

Gets the channel this context represents, None if in a DM. Requires application cache.

get_last_response async #

get_last_response() -> InteractionResponse

Get the last response issued to the interaction this context is proxying.

RETURNS DESCRIPTION
InteractionResponse

The response object.

RAISES DESCRIPTION
RuntimeError

The interaction was not yet responded to.

respond async #

respond(
    content: hikari.UndefinedOr[t.Any] = hikari.UNDEFINED,
    *,
    flags: (
        int | hikari.MessageFlag | hikari.UndefinedType
    ) = hikari.UNDEFINED,
    tts: hikari.UndefinedOr[bool] = hikari.UNDEFINED,
    component: hikari.UndefinedOr[
        hikari.api.ComponentBuilder
    ] = hikari.UNDEFINED,
    components: hikari.UndefinedOr[
        t.Sequence[hikari.api.ComponentBuilder]
    ] = hikari.UNDEFINED,
    attachment: hikari.UndefinedOr[
        hikari.Resourceish
    ] = hikari.UNDEFINED,
    attachments: hikari.UndefinedOr[
        t.Sequence[hikari.Resourceish]
    ] = hikari.UNDEFINED,
    embed: hikari.UndefinedOr[
        hikari.Embed
    ] = hikari.UNDEFINED,
    embeds: hikari.UndefinedOr[
        t.Sequence[hikari.Embed]
    ] = hikari.UNDEFINED,
    mentions_everyone: hikari.UndefinedOr[
        bool
    ] = hikari.UNDEFINED,
    user_mentions: hikari.UndefinedOr[
        hikari.SnowflakeishSequence[hikari.PartialUser]
        | bool
    ] = hikari.UNDEFINED,
    role_mentions: hikari.UndefinedOr[
        hikari.SnowflakeishSequence[hikari.PartialRole]
        | bool
    ] = hikari.UNDEFINED,
    delete_after: hikari.UndefinedOr[
        float | int | datetime.timedelta
    ] = hikari.UNDEFINED
) -> InteractionResponse

Short-hand method to create a new message response via the interaction this context represents.

PARAMETER DESCRIPTION
content

The content of the message. Anything passed here will be cast to str.

TYPE: hikari.UndefinedOr[Any] DEFAULT: hikari.UNDEFINED

tts

If the message should be tts or not.

TYPE: hikari.UndefinedOr[bool] DEFAULT: hikari.UNDEFINED

attachment

An attachment to add to this message.

TYPE: hikari.UndefinedOr[hikari.Resourceish] DEFAULT: hikari.UNDEFINED

attachments

A sequence of attachments to add to this message.

TYPE: hikari.UndefinedOr[t.Sequence[hikari.Resourceish]] DEFAULT: hikari.UNDEFINED

component

A component to add to this message.

TYPE: hikari.UndefinedOr[hikari.api.special_endpoints.ComponentBuilder] DEFAULT: hikari.UNDEFINED

components

A sequence of components to add to this message.

TYPE: hikari.UndefinedOr[t.Sequence[hikari.api.special_endpoints.ComponentBuilder]] DEFAULT: hikari.UNDEFINED

embed

An embed to add to this message.

TYPE: hikari.UndefinedOr[hikari.Embed] DEFAULT: hikari.UNDEFINED

embeds

A sequence of embeds to add to this message.

TYPE: hikari.UndefinedOr[Sequence[hikari.Embed]] DEFAULT: hikari.UNDEFINED

mentions_everyone

If True, mentioning @everyone will be allowed.

TYPE: hikari.UndefinedOr[bool] DEFAULT: hikari.UNDEFINED

user_mentions

The set of allowed user mentions in this message. Set to True to allow all.

TYPE: hikari.UndefinedOr[Union[hikari.SnowflakeishSequence[hikari.PartialUser], bool]] DEFAULT: hikari.UNDEFINED

role_mentions

The set of allowed role mentions in this message. Set to True to allow all.

TYPE: hikari.UndefinedOr[Union[hikari.SnowflakeishSequence[hikari.PartialRole], bool]] DEFAULT: hikari.UNDEFINED

flags

Message flags that should be included with this message.

TYPE: Union[hikari.UndefinedType, int, hikari.MessageFlag] DEFAULT: hikari.UNDEFINED

delete_after

Delete the response after the specified delay.

TYPE: hikari.UndefinedOr[float | int | datetime.timedelta] DEFAULT: hikari.UNDEFINED

RETURNS DESCRIPTION
InteractionResponse

A proxy object representing the response to the interaction.

respond_with_builder async #

respond_with_builder(
    builder: ResponseBuildersT,
) -> InteractionResponse | None

Respond to the interaction with a builder. This method will try to turn the builder into a valid response or followup, depending on the builder type and interaction state.

PARAMETER DESCRIPTION
builder

The builder to respond with.

TYPE: ResponseBuilderT

RETURNS DESCRIPTION
InteractionResponse | None

A proxy object representing the response to the interaction. Will be None if the builder is a modal builder.

RAISES DESCRIPTION
RuntimeError

The interaction was already issued an initial response and the builder can only be used for initial responses.

edit_response async #

edit_response(
    content: hikari.UndefinedNoneOr[
        t.Any
    ] = hikari.UNDEFINED,
    *,
    flags: (
        int | hikari.MessageFlag | hikari.UndefinedType
    ) = hikari.UNDEFINED,
    tts: hikari.UndefinedOr[bool] = hikari.UNDEFINED,
    component: hikari.UndefinedNoneOr[
        hikari.api.ComponentBuilder
    ] = hikari.UNDEFINED,
    components: hikari.UndefinedNoneOr[
        t.Sequence[hikari.api.ComponentBuilder]
    ] = hikari.UNDEFINED,
    attachment: hikari.UndefinedNoneOr[
        hikari.Resourceish
    ] = hikari.UNDEFINED,
    attachments: hikari.UndefinedNoneOr[
        t.Sequence[hikari.Resourceish]
    ] = hikari.UNDEFINED,
    embed: hikari.UndefinedNoneOr[
        hikari.Embed
    ] = hikari.UNDEFINED,
    embeds: hikari.UndefinedNoneOr[
        t.Sequence[hikari.Embed]
    ] = hikari.UNDEFINED,
    mentions_everyone: hikari.UndefinedOr[
        bool
    ] = hikari.UNDEFINED,
    user_mentions: hikari.UndefinedOr[
        hikari.SnowflakeishSequence[hikari.PartialUser]
        | bool
    ] = hikari.UNDEFINED,
    role_mentions: hikari.UndefinedOr[
        hikari.SnowflakeishSequence[hikari.PartialRole]
        | bool
    ] = hikari.UNDEFINED
) -> InteractionResponse

A short-hand method to edit the initial response belonging to this interaction. If no initial response was issued yet, this will create one of type MESSAGE_UPDATE. In the case of modals, this will be the component's message that triggered the modal.

PARAMETER DESCRIPTION
content

The content of the message. Anything passed here will be cast to str.

TYPE: hikari.UndefinedOr[Any] DEFAULT: hikari.UNDEFINED

tts

If the message should be tts or not.

TYPE: hikari.UndefinedOr[bool] DEFAULT: hikari.UNDEFINED

attachment

An attachment to add to this message.

TYPE: hikari.UndefinedOr[hikari.Resourceish] DEFAULT: hikari.UNDEFINED

attachments

A sequence of attachments to add to this message.

TYPE: hikari.UndefinedOr[t.Sequence[hikari.Resourceish]] DEFAULT: hikari.UNDEFINED

component

A component to add to this message.

TYPE: hikari.UndefinedOr[hikari.api.special_endpoints.ComponentBuilder] DEFAULT: hikari.UNDEFINED

components

A sequence of components to add to this message.

TYPE: hikari.UndefinedOr[t.Sequence[hikari.api.special_endpoints.ComponentBuilder]] DEFAULT: hikari.UNDEFINED

embed

An embed to add to this message.

TYPE: hikari.UndefinedOr[hikari.Embed] DEFAULT: hikari.UNDEFINED

embeds

A sequence of embeds to add to this message.

TYPE: hikari.UndefinedOr[Sequence[hikari.Embed]] DEFAULT: hikari.UNDEFINED

mentions_everyone

If True, mentioning @everyone will be allowed.

TYPE: hikari.UndefinedOr[bool] DEFAULT: hikari.UNDEFINED

user_mentions

The set of allowed user mentions in this message. Set to True to allow all.

TYPE: hikari.UndefinedOr[Union[hikari.SnowflakeishSequence[hikari.PartialUser], bool]] DEFAULT: hikari.UNDEFINED

role_mentions

The set of allowed role mentions in this message. Set to True to allow all.

TYPE: hikari.UndefinedOr[Union[hikari.SnowflakeishSequence[hikari.PartialRole], bool]] DEFAULT: hikari.UNDEFINED

flags

Message flags that should be included with this message.

TYPE: Union[hikari.UndefinedType, int, hikari.MessageFlag] DEFAULT: hikari.UNDEFINED

RETURNS DESCRIPTION
InteractionResponse

A proxy object representing the response to the interaction.

defer async #

defer(
    *args: t.Any,
    flags: hikari.UndefinedOr[
        int | hikari.MessageFlag
    ] = hikari.UNDEFINED,
    **kwargs: t.Any
) -> None

Short-hand method to defer an interaction response. Raises RuntimeError if the interaction was already responded to.

PARAMETER DESCRIPTION
response_type

The response-type of this defer action. Defaults to DEFERRED_MESSAGE_UPDATE.

TYPE: hikari.ResponseType

flags

Message flags that should be included with this defer request

TYPE: Union[int, hikari.MessageFlag, None] DEFAULT: hikari.UNDEFINED

RAISES DESCRIPTION
RuntimeError

The interaction was already responded to.

ValueError

response_type was not a deferred response type.