Context
AutocompleteContext
#
Bases: BaseContext
Represents the context for autocomplete interactions
application_id
instance-attribute
#
The ID for the client that this interaction belongs to.
channel_id
instance-attribute
#
The channel ID of the channel that the interaction was used in.
guild_id
instance-attribute
#
The guild ID of the guild that this interaction was used in.
member
instance-attribute
#
The member object for the user that triggered this interaction, if used in a guild.
BaseContext
dataclass
#
Represents the context for interactions
application_id
instance-attribute
#
The ID for the client that this interaction belongs to.
channel_id
instance-attribute
#
The channel ID of the channel that the interaction was used in.
guild_id
instance-attribute
#
The guild ID of the guild that this interaction was used in.
member
instance-attribute
#
The member object for the user that triggered this interaction, if used in a guild.
Context
#
Bases: BaseContext
Represents the context for command interactions
application_id
instance-attribute
#
The ID for the client that this interaction belongs to.
channel
property
#
Get this context's guild channel or thread from the cache.
📝 This will always be
None
for interactions triggered in a DM channel.
channel_id
instance-attribute
#
The channel ID of the channel that the interaction was used in.
guild_id
instance-attribute
#
The guild ID of the guild that this interaction was used in.
member
instance-attribute
#
The member object for the user that triggered this interaction, if used in a guild.
version
instance-attribute
#
version: int
Version of the interaction system this interaction is under.
defer
async
#
defer(ephemeral: bool = False) -> None
Defer this interaction response, allowing you to respond within the next 15 minutes.
edit
async
#
edit(
content: UndefinedNoneOr[Any] = UNDEFINED,
*,
attachment: UndefinedNoneOr[
Resourceish | Attachment
] = UNDEFINED,
attachments: UndefinedNoneOr[
Sequence[Resourceish | Attachment]
] = UNDEFINED,
component: UndefinedNoneOr[
ComponentBuilder
] = UNDEFINED,
components: UndefinedNoneOr[
Sequence[ComponentBuilder]
] = UNDEFINED,
embed: UndefinedNoneOr[Embed] = UNDEFINED,
embeds: UndefinedNoneOr[Sequence[Embed]] = UNDEFINED,
mentions_everyone: UndefinedOr[bool] = UNDEFINED,
user_mentions: UndefinedOr[
SnowflakeishSequence[PartialUser] | bool
] = UNDEFINED,
role_mentions: UndefinedOr[
SnowflakeishSequence[PartialRole] | bool
] = UNDEFINED
) -> Message
Edit the previous response to this interaction.
Example#
import asyncio
@client.include
@crescent.command
async def command(ctx: crescent.Context):
await ctx.respond("hello there")
await asyncio.sleep(3)
await ctx.edit("general kenobi")
📝 Message flags are ignored in followup responses.
PARAMETER | DESCRIPTION |
---|---|
content |
The content to send.
TYPE:
|
attachment |
A single attachment to send.
TYPE:
|
attachments |
A list of attachments to send.
TYPE:
|
component |
A single component to send.
TYPE:
|
components |
A list of components to send.
TYPE:
|
embed |
A single embed to send.
TYPE:
|
embeds |
A list of embeds to send.
TYPE:
|
mentions_everyone |
Allow
TYPE:
|
user_mentions |
If
TYPE:
|
role_mentions |
If
TYPE:
|
respond
async
#
respond(
content: UndefinedOr[Any] = UNDEFINED,
*,
ephemeral: bool = False,
flags: int | MessageFlag | UndefinedType = UNDEFINED,
tts: UndefinedOr[bool] = UNDEFINED,
attachment: UndefinedOr[Resourceish] = UNDEFINED,
attachments: UndefinedOr[
Sequence[Resourceish]
] = UNDEFINED,
component: UndefinedOr[ComponentBuilder] = UNDEFINED,
components: UndefinedOr[
Sequence[ComponentBuilder]
] = UNDEFINED,
embed: UndefinedOr[Embed] = UNDEFINED,
embeds: UndefinedOr[Sequence[Embed]] = UNDEFINED,
mentions_everyone: UndefinedOr[bool] = UNDEFINED,
user_mentions: UndefinedOr[
SnowflakeishSequence[PartialUser] | bool
] = UNDEFINED,
role_mentions: UndefinedOr[
SnowflakeishSequence[PartialRole] | bool
] = UNDEFINED,
ensure_message: bool = False
) -> Message | None
Respond to an interaction. This function can be used multiple times for one interaction,
Example#
@client.include
@crescent.command
async def command(ctx: crescent.Context):
# Initial response
await ctx.respond("hello")
# After the first response, a followup response will be sent.
await ctx.respond("word")
📝 Message flags are ignored in followup responses.
PARAMETER | DESCRIPTION |
---|---|
content |
The content to send.
TYPE:
|
ephermial |
Send this message as ephermial if set to true. Ephermial messages can be dismissed by the user, similar to Clyde messages. This kwarg only affects the initial response to an interaction.
|
flags |
Message flags to send with the message. You do not need to use
this, and exists for compatibility in the future. Instead set
the
TYPE:
|
tts |
If true, send a text to speech message.
TYPE:
|
attachment |
A single attachment to send.
TYPE:
|
attachments |
A list of attachments to send.
TYPE:
|
component |
A single component to send.
TYPE:
|
components |
A list of components to send.
TYPE:
|
embed |
A single embed to send.
TYPE:
|
embeds |
A list of embeds to send.
TYPE:
|
mentions_everyone |
Allow
TYPE:
|
user_mentions |
If
TYPE:
|
role_mentions |
If
TYPE:
|
ensure_message |
A message is not returned the first time you use
TYPE:
|
respond_with_builder
async
#
respond_with_builder(
builder: ResponseBuilderT, ensure_message: bool = False
) -> Message | None
Respond to an interaction with a builder.
PARAMETER | DESCRIPTION |
---|---|
builder |
The builder to respond with.
TYPE:
|
ensure_message |
If an InteractionMessageBuilder is passed, this will fetch the message and return it. Otherwise does nothing.
TYPE:
|
RAISES | DESCRIPTION |
---|---|
InteractionAlreadyAcknowledgedError
|
Raised when calling this method after responding to an interaction. |
RETURNS | DESCRIPTION |
---|---|
Message | None
|
The message if |
respond_with_modal
async
#
Respond to an interaction with a modal.
PARAMETER | DESCRIPTION |
---|---|
title |
The title of the modal.
TYPE:
|
custom_id |
The custom id of the modal.
TYPE:
|
components |
The components to add to the modal.
TYPE:
|
RAISES | DESCRIPTION |
---|---|
InteractionAlreadyAcknowledgedError
|
Raised when calling this method after responding to an interaction. |
get_context_type
#
get_context_type(
sig: Signature,
) -> type[BaseContext] | None
Returns the Context type the function uses or None
if the function is not annotated with
a subclass of BaseContext
get_function_context
#
get_function_context(
func: Callable[..., Any]
) -> type[BaseContext]
Gets the context type used in a function.