Context ABC API Reference#
InteractionResponse
#
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
#
retrieve_message
async
#
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 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:
|
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. |
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. |
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
#
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
#
responses: t.Sequence[InteractionResponse]
A list of all responses issued to the interaction this context is proxying.
member
property
#
member: hikari.InteractionMember | None
The member who triggered this interaction. 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.
app_permissions
property
#
app_permissions: hikari.Permissions | None
The permissions of the bot. Will be None in DMs.
guild_id
property
#
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:
|
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 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:
|
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:
|
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:
|
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:
|
flags |
Message flags that should be included with this defer request
TYPE:
|
RAISES | DESCRIPTION |
---|---|
RuntimeError
|
The interaction was already responded to. |
ValueError
|
response_type was not a deferred response type. |