Skip to content

Context

AutocompleteContext #

Bases: BaseContext

Represents the context for autocomplete interactions

app instance-attribute #

The application instance.

application_id instance-attribute #

application_id: Snowflake

The ID for the client that this interaction belongs to.

channel_id instance-attribute #

channel_id: Snowflake

The channel ID of the channel that the interaction was used in.

client instance-attribute #

client: Client

The crescent Client instance.

command instance-attribute #

command: str

The name of the command.

guild_id instance-attribute #

guild_id: Snowflake | None

The guild ID of the guild that this interaction was used in.

id instance-attribute #

id: Snowflake

The ID of the interaction.

interaction instance-attribute #

interaction: AutocompleteInteraction

The interaction object.

member instance-attribute #

member: Member | None

The member object for the user that triggered this interaction, if used in a guild.

options instance-attribute #

options: dict[str, Any]

The options that were provided by the user.

token instance-attribute #

token: str

The token for the interaction.

type instance-attribute #

type: int

The type of the interaction.

user instance-attribute #

user: User

The user who triggered this command interaction.

version instance-attribute #

version: int

Version of the interaction system this interaction is under.

into #

into(context_t: Type[ContextT]) -> ContextT

Convert to a context of a different type.

BaseContext dataclass #

Represents the context for interactions

app instance-attribute #

The application instance.

application_id instance-attribute #

application_id: Snowflake

The ID for the client that this interaction belongs to.

channel_id instance-attribute #

channel_id: Snowflake

The channel ID of the channel that the interaction was used in.

client instance-attribute #

client: Client

The crescent Client instance.

command instance-attribute #

command: str

The name of the command.

guild_id instance-attribute #

guild_id: Snowflake | None

The guild ID of the guild that this interaction was used in.

id instance-attribute #

id: Snowflake

The ID of the interaction.

interaction instance-attribute #

interaction: PartialInteraction

The interaction object.

member instance-attribute #

member: Member | None

The member object for the user that triggered this interaction, if used in a guild.

options instance-attribute #

options: dict[str, Any]

The options that were provided by the user.

token instance-attribute #

token: str

The token for the interaction.

type instance-attribute #

type: int

The type of the interaction.

user instance-attribute #

user: User

The user who triggered this command interaction.

version instance-attribute #

version: int

Version of the interaction system this interaction is under.

into #

into(context_t: Type[ContextT]) -> ContextT

Convert to a context of a different type.

Context #

Bases: BaseContext

Represents the context for command interactions

app instance-attribute #

The application instance.

application_id instance-attribute #

application_id: Snowflake

The ID for the client that this interaction belongs to.

channel property #

channel: PermissibleGuildChannel | GuildThreadChannel | None

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 #

channel_id: Snowflake

The channel ID of the channel that the interaction was used in.

client instance-attribute #

client: Client

The crescent Client instance.

command instance-attribute #

command: str

The name of the command.

guild property #

guild: GatewayGuild | None

Get this context's guild from the cache.

guild_id instance-attribute #

guild_id: Snowflake | None

The guild ID of the guild that this interaction was used in.

id instance-attribute #

id: Snowflake

The ID of the interaction.

interaction instance-attribute #

interaction: CommandInteraction

The interaction object.

member instance-attribute #

member: Member | None

The member object for the user that triggered this interaction, if used in a guild.

options instance-attribute #

options: dict[str, Any]

The options that were provided by the user.

token instance-attribute #

token: str

The token for the interaction.

type instance-attribute #

type: int

The type of the interaction.

user instance-attribute #

user: User

The user who triggered this command interaction.

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.

delete async #

delete() -> None

Delete the previous response to this interaction.

Example#
import asyncio

@client.include
@crescent.command
async def command(ctx: crescent.Context):
    await ctx.respond("im going to disappear")
    await asyncio.sleep(3)
    await ctx.delete()

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: UndefinedNoneOr[Any] DEFAULT: UNDEFINED

attachment

A single attachment to send.

TYPE: UndefinedNoneOr[Resourceish | Attachment] DEFAULT: UNDEFINED

attachments

A list of attachments to send.

TYPE: UndefinedNoneOr[Sequence[Resourceish | Attachment]] DEFAULT: UNDEFINED

component

A single component to send.

TYPE: UndefinedNoneOr[ComponentBuilder] DEFAULT: UNDEFINED

components

A list of components to send.

TYPE: UndefinedNoneOr[Sequence[ComponentBuilder]] DEFAULT: UNDEFINED

embed

A single embed to send.

TYPE: UndefinedNoneOr[Embed] DEFAULT: UNDEFINED

embeds

A list of embeds to send.

TYPE: UndefinedNoneOr[Sequence[Embed]] DEFAULT: UNDEFINED

mentions_everyone

Allow @everyone and @here to ping users if set to True.

TYPE: UndefinedOr[bool] DEFAULT: UNDEFINED

user_mentions

If True, all mentioned users will be sent a notification. If a list of users is provided, only those users will be mentioned.

TYPE: UndefinedOr[SnowflakeishSequence[PartialUser] | bool] DEFAULT: UNDEFINED

role_mentions

If True, all mentioned roles will be sent a notification. If a list of roles is provided, only those roles will be mentioned.

TYPE: UndefinedOr[SnowflakeishSequence[PartialRole] | bool] DEFAULT: UNDEFINED

into #

into(context_t: Type[ContextT]) -> ContextT

Convert to a context of a different 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: UndefinedOr[Any] DEFAULT: UNDEFINED

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 ephermial kwarg to True.

TYPE: int | MessageFlag | UndefinedType DEFAULT: UNDEFINED

tts

If true, send a text to speech message.

TYPE: UndefinedOr[bool] DEFAULT: UNDEFINED

attachment

A single attachment to send.

TYPE: UndefinedOr[Resourceish] DEFAULT: UNDEFINED

attachments

A list of attachments to send.

TYPE: UndefinedOr[Sequence[Resourceish]] DEFAULT: UNDEFINED

component

A single component to send.

TYPE: UndefinedOr[ComponentBuilder] DEFAULT: UNDEFINED

components

A list of components to send.

TYPE: UndefinedOr[Sequence[ComponentBuilder]] DEFAULT: UNDEFINED

embed

A single embed to send.

TYPE: UndefinedOr[Embed] DEFAULT: UNDEFINED

embeds

A list of embeds to send.

TYPE: UndefinedOr[Sequence[Embed]] DEFAULT: UNDEFINED

mentions_everyone

Allow @everyone and @here to ping users if set to True.

TYPE: UndefinedOr[bool] DEFAULT: UNDEFINED

user_mentions

If True, all mentioned users will be sent a notification. If a list of users is provided, only those users will be mentioned.

TYPE: UndefinedOr[SnowflakeishSequence[PartialUser] | bool] DEFAULT: UNDEFINED

role_mentions

If True, all mentioned roles will be sent a notification. If a list of roles is provided, only those roles will be mentioned.

TYPE: UndefinedOr[SnowflakeishSequence[PartialRole] | bool] DEFAULT: UNDEFINED

ensure_message

A message is not returned the first time you use Context.respond. Set ensure_message=True to automatically fetch a message and return it.

TYPE: bool DEFAULT: False

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: ResponseBuilderT

ensure_message

If an InteractionMessageBuilder is passed, this will fetch the message and return it. Otherwise does nothing.

TYPE: bool DEFAULT: False

RAISES DESCRIPTION
InteractionAlreadyAcknowledgedError

Raised when calling this method after responding to an interaction.

RETURNS DESCRIPTION
Message | None

The message if ensure_message is True and a message builder was passed.

respond_with_modal async #

respond_with_modal(
    title: str,
    custom_id: str,
    components: Sequence[ComponentBuilder],
) -> None

Respond to an interaction with a modal.

PARAMETER DESCRIPTION
title

The title of the modal.

TYPE: str

custom_id

The custom id of the modal.

TYPE: str

components

The components to add to the modal.

TYPE: Sequence[ComponentBuilder]

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.

support_custom_context #

support_custom_context(
    func: Callable[P, Awaitable[T]]
) -> Callable[P, Awaitable[tuple[T, BaseContext]]]

Returns a function that is called with the context type it is annotated with.