Skip to content

Context#

AutodeferMode #

Bases: IntEnum

An enum representing autodefer configuration.

EPHEMERAL class-attribute instance-attribute #

EPHEMERAL = 2

Autodefer and make the response ephemeral if the command takes longer than 2 seconds to respond.

OFF class-attribute instance-attribute #

OFF = 0

Do not autodefer.

ON class-attribute instance-attribute #

ON = 1

Autodefer if the command takes longer than 2 seconds to respond.

should_autodefer property #

should_autodefer: bool

Whether this mode should autodefer.

Context #

Context(
    client: ClientT,
    command: CallableCommandProto[ClientT],
    interaction: CommandInteraction,
)

Bases: Generic[ClientT]

A context object that is proxying a Discord command interaction.

app_permissions property #

app_permissions: Permissions | None

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

author property #

author: User

Alias for Context.user.

channel_id property #

channel_id: Snowflake

The ID of the channel the context represents.

client property #

client: ClientT

The client that included the command.

command property #

command: CallableCommandProto[ClientT]

The command that was invoked.

guild_id property #

guild_id: Snowflake | None

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

guild_locale property #

guild_locale: str | Locale | None

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

has_command_failed property #

has_command_failed: bool

Returns if the command callback failed to execute or not.

interaction property #

interaction: CommandInteraction

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, you should disable the autodefer feature in your command.

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.

locale property #

locale: str | Locale

The locale of this context.

member property #

member: InteractionMember | None

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

responses property #

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

user property #

user: User

The user who triggered this interaction.

defer async #

defer(flags: int | MessageFlag | UndefinedType = hikari.UNDEFINED) -> None

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

PARAMETER DESCRIPTION
flags

Message flags that should be included with this defer request

TYPE: int | MessageFlag | UndefinedType DEFAULT: UNDEFINED

RAISES DESCRIPTION
ResponseAlreadyIssuedError

The interaction was already issued an initial response.

edit_initial_response async #

edit_initial_response(
    content: Any | None | UndefinedType = hikari.UNDEFINED,
    *,
    attachment: Resourceish | None | UndefinedType = hikari.UNDEFINED,
    attachments: (
        Sequence[Resourceish] | None | UndefinedType
    ) = hikari.UNDEFINED,
    component: ComponentBuilder | None | UndefinedType = hikari.UNDEFINED,
    components: (
        Sequence[ComponentBuilder] | None | UndefinedType
    ) = hikari.UNDEFINED,
    embed: Embed | None | UndefinedType = hikari.UNDEFINED,
    embeds: Sequence[Embed] | None | UndefinedType = hikari.UNDEFINED,
    mentions_everyone: bool | UndefinedType = hikari.UNDEFINED,
    user_mentions: (
        Sequence[Snowflakeish | PartialUser] | bool | UndefinedType
    ) = hikari.UNDEFINED,
    role_mentions: (
        Sequence[Snowflake | PartialRole] | bool | UndefinedType
    ) = hikari.UNDEFINED
) -> InteractionResponse

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

If you want to edit a followup, you should use the edit() method of the returned InteractionResponse response object instead.

PARAMETER DESCRIPTION
content

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

TYPE: Any | None | UndefinedType DEFAULT: UNDEFINED

attachment

An attachment to add to this message.

TYPE: Resourceish | None | UndefinedType DEFAULT: UNDEFINED

attachments

A sequence of attachments to add to this message.

TYPE: Sequence[Resourceish] | None | UndefinedType DEFAULT: UNDEFINED

component

A component to add to this message.

TYPE: ComponentBuilder | None | UndefinedType DEFAULT: UNDEFINED

components

A sequence of components to add to this message.

TYPE: Sequence[ComponentBuilder] | None | UndefinedType DEFAULT: UNDEFINED

embed

An embed to add to this message.

TYPE: Embed | None | UndefinedType DEFAULT: UNDEFINED

embeds

A sequence of embeds to add to this message.

TYPE: Sequence[Embed] | None | UndefinedType DEFAULT: UNDEFINED

mentions_everyone

If True, mentioning @everyone will be allowed.

TYPE: bool | UndefinedType DEFAULT: UNDEFINED

user_mentions

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

TYPE: Sequence[Snowflakeish | PartialUser] | bool | UndefinedType DEFAULT: UNDEFINED

role_mentions

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

TYPE: Sequence[Snowflakeish | PartialRole] | bool | UndefinedType DEFAULT: UNDEFINED

RETURNS DESCRIPTION
InteractionResponse

A proxy object representing the response to the interaction.

RAISES DESCRIPTION
NoResponseIssuedError

The interaction was not yet issued an initial response.

get_channel #

get_channel() -> TextableGuildChannel | None

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

get_guild #

get_guild() -> GatewayGuild | None

Gets the guild this context represents, if any. 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.

get_option #

get_option(name: str, opt_type: OptionType) -> Any | None

Get the value of an option by name.

PARAMETER DESCRIPTION
name

The name of the option.

TYPE: str

opt_type

The type of the option.

TYPE: OptionType

RETURNS DESCRIPTION
ValueT | None

The value of the option, or None if it does not exist, or is not of the correct type.

Example
value = ctx.get_option("name", arc.OptionType.STRING)
if value is None:
    # Option does not exist or is not a string

# Do something with the value
print(value)

get_type_dependency #

get_type_dependency(
    type_: type[T], *, default: DefaultT | UndefinedType = hikari.UNDEFINED
) -> T | DefaultT

Get a type dependency for the current context.

PARAMETER DESCRIPTION
type_

The type of the dependency.

TYPE: type[T]

default

The default value to return if the dependency does not exist. If not provided, this will raise an exception if the dependency does not exist.

TYPE: DefaultT DEFAULT: UNDEFINED

RETURNS DESCRIPTION
T | DefaultT

The instance of the dependency, if it exists, otherwise default.

RAISES DESCRIPTION
KeyError

If the dependency does not exist and default was not provided.

loc #

loc(
    key: str,
    use_guild: bool = True,
    force_locale: Locale | None = None,
    **kwargs: Any
) -> str

Get a localized string using the interaction's locale.

PARAMETER DESCRIPTION
key

The key of the string to localize.

TYPE: str

use_guild

Whether to use the guild or not, if in a guild.

TYPE: bool DEFAULT: True

force_locale

Force a locale to use, instead of the context's locale.

TYPE: Locale | None DEFAULT: None

kwargs

The keyword arguments to pass to the string formatter.

TYPE: Any DEFAULT: {}

RETURNS DESCRIPTION
str

The localized string.

respond async #

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

Short-hand method to create a new message response via the interaction this context represents. This function automatically determines if the response should be an initial response or a followup.

PARAMETER DESCRIPTION
content

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

TYPE: Any | UndefinedType DEFAULT: UNDEFINED

tts

If the message should be tts or not.

TYPE: bool | UndefinedType DEFAULT: UNDEFINED

attachment

An attachment to add to this message.

TYPE: Resourceish | UndefinedType DEFAULT: UNDEFINED

attachments

A sequence of attachments to add to this message.

TYPE: Sequence[Resourceish] | UndefinedType DEFAULT: UNDEFINED

component

A component to add to this message.

TYPE: ComponentBuilder | UndefinedType DEFAULT: UNDEFINED

components

A sequence of components to add to this message.

TYPE: Sequence[ComponentBuilder] | UndefinedType DEFAULT: UNDEFINED

embed

An embed to add to this message.

TYPE: Embed | UndefinedType DEFAULT: UNDEFINED

embeds

A sequence of embeds to add to this message.

TYPE: Sequence[Embed] | UndefinedType DEFAULT: UNDEFINED

mentions_everyone

If True, mentioning @everyone will be allowed.

TYPE: bool | UndefinedType DEFAULT: UNDEFINED

user_mentions

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

TYPE: SnowflakeishSequence[PartialUser] | bool | UndefinedType DEFAULT: UNDEFINED

role_mentions

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

TYPE: SnowflakeishSequence[PartialRole] | bool | UndefinedType DEFAULT: UNDEFINED

flags

Message flags that should be included with this message.

TYPE: int | MessageFlag | UndefinedType DEFAULT: UNDEFINED

delete_after

Delete the response after the specified delay.

TYPE: float | int | timedelta | UndefinedType DEFAULT: UNDEFINED

RETURNS DESCRIPTION
InteractionResponse

A proxy object representing the message response to the interaction.

respond_with_builder async #

respond_with_builder(builder: ResponseBuilderT) -> 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.

respond_with_modal async #

respond_with_modal(
    title: str, custom_id: str, *, components: Sequence[ComponentBuilder]
) -> None

Respond to the interaction with a modal. Note that this must be the first response issued to the interaction. If you're using miru, or already have an interaction builder, use respond_with_builder instead.

PARAMETER DESCRIPTION
title

The title of the modal.

TYPE: str

custom_id

The custom ID of the modal.

TYPE: str

components

The list of hikari component builders to add to the modal.

TYPE: Sequence[ComponentBuilder]

RAISES DESCRIPTION
ResponseAlreadyIssuedError

The interaction was already issued an initial response.

InteractionResponse #

InteractionResponse(context: Context[Any], message: Message | None = None)

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

delete async #

delete() -> None

Delete the response issued to the interaction this object represents.

delete_after #

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

Delete the response after the specified delay.

PARAMETER DESCRIPTION
delay

The delay after which the response should be deleted.

TYPE: int | float | timedelta

edit async #

edit(
    content: Any | UndefinedType | None = hikari.UNDEFINED,
    *,
    component: ComponentBuilder | UndefinedType | None = hikari.UNDEFINED,
    components: (
        Sequence[ComponentBuilder] | UndefinedType | None
    ) = hikari.UNDEFINED,
    attachment: Resourceish | UndefinedType | None = hikari.UNDEFINED,
    attachments: (
        Sequence[Resourceish] | UndefinedType | None
    ) = hikari.UNDEFINED,
    embed: Embed | UndefinedType | None = hikari.UNDEFINED,
    embeds: Sequence[Embed] | UndefinedType | None = hikari.UNDEFINED,
    mentions_everyone: bool | UndefinedType = hikari.UNDEFINED,
    user_mentions: (
        Sequence[Snowflakeish | PartialUser] | bool | UndefinedType
    ) = hikari.UNDEFINED,
    role_mentions: (
        Sequence[Snowflakeish | PartialRole] | bool | UndefinedType
    ) = 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: Any | UndefinedType DEFAULT: UNDEFINED

attachment

An attachment to add to this message.

TYPE: Resourceish | UndefinedType DEFAULT: UNDEFINED

attachments

A sequence of attachments to add to this message.

TYPE: Sequence[Resourceish] | UndefinedType DEFAULT: UNDEFINED

component

A component to add to this message.

TYPE: ComponentBuilder | UndefinedType DEFAULT: UNDEFINED

components

A sequence of components to add to this message.

TYPE: Sequence[ComponentBuilder] | UndefinedType DEFAULT: UNDEFINED

embed

An embed to add to this message.

TYPE: Embed | UndefinedType DEFAULT: UNDEFINED

embeds

A sequence of embeds to add to this message.

TYPE: Sequence[Embed] | UndefinedType DEFAULT: UNDEFINED

mentions_everyone

If True, mentioning @everyone will be allowed.

TYPE: bool | UndefinedType DEFAULT: UNDEFINED

user_mentions

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

TYPE: Sequence[Snowflakish | PartialUser] | bool | UndefinedType DEFAULT: UNDEFINED

role_mentions

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

TYPE: Sequence[Snowflakish | PartialRole] | bool | UndefinedType DEFAULT: UNDEFINED

RETURNS DESCRIPTION
InteractionResponse

A proxy object representing the response to the interaction.

retrieve_message async #

retrieve_message() -> 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
Message

The message created by this response.

AutocompleteData #

Bases: Generic[ClientT, ChoiceT]

The data that is provided to an autocomplete callback.

channel_id property #

channel_id: Snowflake

The channel ID of the interaction.

client instance-attribute #

client: ClientT

The client that received the autocomplete.

command instance-attribute #

command: CommandProto

The command that needs to be autocompleted.

focused_option cached property #

focused_option: AutocompleteInteractionOption | None

The option that is currently being focused.

focused_value cached property #

focused_value: ChoiceT | str | None

The value that is currently being focused. This property will return None if there is no focused option.

Warning

This property may not parsed by the client yet, in that case it is returned as a str.

Tip

According to some testing, this option is always either None or a string, however the API documentation says that it can be the option type as well.

guild_id property #

guild_id: Snowflake | None

The guild ID of the interaction.

interaction instance-attribute #

The interaction that triggered the autocomplete.

member property #

member: Member | None

The member that triggered the interaction.

options instance-attribute #

The options that have been provided so far.

user property #

user: User

The user that triggered the interaction.

get_channel #

get_channel() -> TextableGuildChannel | None

Get the channel that triggered the interaction.

get_guild #

get_guild() -> Guild | None

Get the guild that triggered the interaction.