Context API Reference#
ModalContext
#
ModalContext(
modal: Modal,
client: Client,
interaction: hikari.ModalInteraction,
values: t.Mapping[ModalItem, str],
)
Bases: Context[hikari.ModalInteraction]
A context object proxying a ModalInteraction received by a miru modal.
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. |
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. |
respond_with_builder
async
#
respond_with_builder(
builder: ModalResponseBuildersT,
) -> InteractionResponse
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
|
The response that was sent. |
RAISES | DESCRIPTION |
---|---|
RuntimeError
|
The interaction was already responded to. |
get_value_by
#
get_value_by(
predicate: t.Callable[[ModalItem], bool],
*,
default: T | hikari.UndefinedType = hikari.UNDEFINED
) -> str | T
Get the value for the first modal item that matches the given predicate.
PARAMETER | DESCRIPTION |
---|---|
predicate |
A predicate to match the item. |
default |
A default value to return if no item was matched |
RETURNS | DESCRIPTION |
---|---|
T | str
|
The value of the item that matched the predicate or the default value. |
RAISES | DESCRIPTION |
---|---|
KeyError
|
The item was not found and no default was provided. |
get_value_by_id
#
get_value_by_id(
custom_id: str,
default: T | hikari.UndefinedType = hikari.UNDEFINED,
) -> T | str
Get the value for a modal item with the given custom ID.
PARAMETER | DESCRIPTION |
---|---|
custom_id |
The custom_id of the component.
TYPE:
|
default |
A default value to return if the item was not found |
RETURNS | DESCRIPTION |
---|---|
T | str
|
The value of the item with the given custom ID or the default value. |
RAISES | DESCRIPTION |
---|---|
KeyError
|
The item was not found and no default was provided. |
AutodeferMode
#
AutodeferOptions
#
AutodeferOptions(
mode: AutodeferMode,
response_type: (
t.Literal[
hikari.ResponseType.DEFERRED_MESSAGE_CREATE
]
| t.Literal[
hikari.ResponseType.DEFERRED_MESSAGE_UPDATE
]
),
)
response_type
property
#
response_type: hikari.ResponseType
The response type to use when autodefering.
ViewContext
#
ViewContext(
view: View,
client: Client,
interaction: hikari.ComponentInteraction,
)
Bases: Context[hikari.ComponentInteraction]
A context object proxying a ComponentInteraction for a view item.
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.
message
property
#
The message object for the view this context is proxying.
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. |
respond_with_modal
async
#
respond_with_modal(modal: Modal) -> None
Respond to this interaction with a modal.
This is effectively the same as:
builder = modal.build_response(client)
await ctx.respond_with_builder(builder)
client.start_modal(modal)
PARAMETER | DESCRIPTION |
---|---|
modal |
The modal to respond with.
TYPE:
|