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.
authorizing_guild_id
property
#
authorizing_guild_id: Snowflake | None
The ID of the guild that this command was installed in.
This will be None
if the command was not installed in the guild.
This is a shorthand for
Note
It is possible for both this value and authorizing_user_id
to not be None
, if the command is installed
in both a guild and by a user.
authorizing_integration_owners
property
#
authorizing_integration_owners: Mapping[ApplicationIntegrationType, Snowflake]
Includes details about the authorizing user or guild for the installation(s) relevant to the interaction.
For apps installed to a user, it can be used to tell the difference between the authorizing user and the user that triggered an interaction.
authorizing_user_id
property
#
authorizing_user_id: Snowflake | None
The ID of the user that installed this command.
This will be None
if the command was not installed by a user.
This is a shorthand for
Note
It is possible for both this value and authorizing_guild_id
to not be None
, if the command is installed
in both a guild and by a user.
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.
invocation_context
property
#
invocation_context: ApplicationContextType
The context in which the interaction was invoked.
This can be used to determine if the command was invoked in DMs, a guild, or a group DM.
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 = 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 = UNDEFINED,
*,
attachment: Resourceish | None | UndefinedType = UNDEFINED,
attachments: Sequence[Resourceish] | None | UndefinedType = UNDEFINED,
component: ComponentBuilder | None | UndefinedType = UNDEFINED,
components: Sequence[ComponentBuilder] | None | UndefinedType = UNDEFINED,
embed: Embed | None | UndefinedType = UNDEFINED,
embeds: Sequence[Embed] | None | UndefinedType = UNDEFINED,
mentions_everyone: bool | UndefinedType = UNDEFINED,
user_mentions: (
Sequence[Snowflakeish | PartialUser] | bool | UndefinedType
) = UNDEFINED,
role_mentions: (
Sequence[Snowflake | PartialRole] | bool | UndefinedType
) = 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_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: Literal[ATTACHMENT]) -> Attachment | None
get_option(name: str, opt_type: Literal[MENTIONABLE]) -> User | Role | None
get_option(name: str, opt_type: Literal[CHANNEL]) -> PartialChannel | None
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]) -> T
get_type_dependency(type_: type[T], *, default: DefaultT) -> T | DefaultT
get_type_dependency(
type_: type[T], *, default: DefaultT | UndefinedType = 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 = UNDEFINED,
*,
flags: int | MessageFlag | UndefinedType = UNDEFINED,
tts: bool | UndefinedType = UNDEFINED,
attachment: Resourceish | UndefinedType = UNDEFINED,
attachments: Sequence[Resourceish] | UndefinedType = UNDEFINED,
component: ComponentBuilder | UndefinedType = UNDEFINED,
components: Sequence[ComponentBuilder] | UndefinedType = UNDEFINED,
embed: Embed | UndefinedType = UNDEFINED,
embeds: Sequence[Embed] | UndefinedType = UNDEFINED,
mentions_everyone: bool | UndefinedType = UNDEFINED,
user_mentions: (
Sequence[Snowflakeish | PartialUser] | bool | UndefinedType
) = UNDEFINED,
role_mentions: (
Sequence[Snowflake | PartialRole] | bool | UndefinedType
) = UNDEFINED,
delete_after: float | int | timedelta | UndefinedType = 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: InteractionModalBuilder) -> None
respond_with_builder(
builder: InteractionMessageBuilder | InteractionDeferredBuilder,
) -> InteractionResponse
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 = UNDEFINED,
*,
component: ComponentBuilder | UndefinedType | None = UNDEFINED,
components: Sequence[ComponentBuilder] | UndefinedType | None = UNDEFINED,
attachment: Resourceish | UndefinedType | None = UNDEFINED,
attachments: Sequence[Resourceish] | UndefinedType | None = UNDEFINED,
embed: Embed | UndefinedType | None = UNDEFINED,
embeds: Sequence[Embed] | UndefinedType | None = UNDEFINED,
mentions_everyone: bool | UndefinedType = UNDEFINED,
user_mentions: (
Sequence[Snowflakeish | PartialUser] | bool | UndefinedType
) = UNDEFINED,
role_mentions: (
Sequence[Snowflakeish | PartialRole] | bool | UndefinedType
) = 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.
authorizing_integration_owners
property
#
authorizing_integration_owners: Mapping[ApplicationIntegrationType, Snowflake]
Includes details about the authorizing user or server for the installation(s) relevant to the interaction.
For apps installed to a user, it can be used to tell the difference between the authorizing user and the user that triggered an interaction (like a message component).
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.
invocation_context
property
#
invocation_context: ApplicationContextType
The context in which the interaction was invoked.
options
instance-attribute
#
options: Sequence[AutocompleteInteractionOption]
The options that have been provided so far.