Context#
AutodeferMode
#
Bases: IntEnum
An enum representing autodefer configuration.
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.
guild_id
property
#
guild_id: Snowflake | None
The ID of the guild the context represents. Will be None in DMs.
guild_locale
property
#
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.
member
property
#
member: InteractionMember | None
The member who triggered this interaction. Will be None in DMs.
responses
property
#
responses: Sequence[InteractionResponse]
A list of all responses issued to the interaction this context is proxying.
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:
|
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:
|
attachment |
An attachment to add to this message.
TYPE:
|
attachments |
A sequence of attachments to add to this message.
TYPE:
|
component |
A component to add to this message.
TYPE:
|
components |
A sequence of components to add to this message.
TYPE:
|
embed |
An embed to add to this message.
TYPE:
|
embeds |
A sequence of embeds to add to this message.
TYPE:
|
mentions_everyone |
If True, mentioning @everyone will be allowed.
TYPE:
|
user_mentions |
The set of allowed user mentions in this message. Set to True to allow all.
TYPE:
|
role_mentions |
The set of allowed role mentions in this message. Set to True to allow all.
TYPE:
|
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:
|
opt_type |
The type of the option.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
ValueT | None
|
The value of the option, or None if it does not exist, or is not of the correct type. |
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:
|
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:
|
RETURNS | DESCRIPTION |
---|---|
T | DefaultT
|
The instance of the dependency, if it exists, otherwise |
RAISES | DESCRIPTION |
---|---|
KeyError
|
If the dependency does not exist and |
loc
#
Get a localized string using the interaction's locale.
PARAMETER | DESCRIPTION |
---|---|
key |
The key of the string to localize.
TYPE:
|
use_guild |
Whether to use the guild or not, if in a guild.
TYPE:
|
force_locale |
Force a locale to use, instead of the context's locale.
TYPE:
|
kwargs |
The keyword arguments to pass to the string formatter.
TYPE:
|
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:
|
tts |
If the message should be tts or not.
TYPE:
|
attachment |
An attachment to add to this message.
TYPE:
|
attachments |
A sequence of attachments to add to this message.
TYPE:
|
component |
A component to add to this message.
TYPE:
|
components |
A sequence of components to add to this message.
TYPE:
|
embed |
An embed to add to this message.
TYPE:
|
embeds |
A sequence of embeds to add to this message.
TYPE:
|
mentions_everyone |
If True, mentioning @everyone will be allowed.
TYPE:
|
user_mentions |
The set of allowed user mentions in this message. Set to True to allow all.
TYPE:
|
role_mentions |
The set of allowed role mentions in this message. Set to True to allow all.
TYPE:
|
flags |
Message flags that should be included with this message.
TYPE:
|
delete_after |
Delete the response after the specified delay.
TYPE:
|
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:
|
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:
|
custom_id |
The custom ID of the modal.
TYPE:
|
components |
The list of hikari component builders to add to the modal.
TYPE:
|
RAISES | DESCRIPTION |
---|---|
ResponseAlreadyIssuedError
|
The interaction was already issued an initial response. |
InteractionResponse
#
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 the response issued to the interaction this object represents.
delete_after
#
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:
|
attachment |
An attachment to add to this message.
TYPE:
|
attachments |
A sequence of attachments to add to this message.
TYPE:
|
component |
A component to add to this message.
TYPE:
|
components |
A sequence of components to add to this message.
TYPE:
|
embed |
An embed to add to this message.
TYPE:
|
embeds |
A sequence of embeds to add to this message.
TYPE:
|
mentions_everyone |
If True, mentioning @everyone will be allowed.
TYPE:
|
user_mentions |
The set of allowed user mentions in this message. Set to True to allow all.
TYPE:
|
role_mentions |
The set of allowed role mentions in this message. Set to True to allow all.
TYPE:
|
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.
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.
interaction
instance-attribute
#
interaction: AutocompleteInteraction
The interaction that triggered the autocomplete.
options
instance-attribute
#
options: Sequence[AutocompleteInteractionOption]
The options that have been provided so far.
get_channel
#
get_channel() -> TextableGuildChannel | None
Get the channel that triggered the interaction.