Skip to content

Context

AutocompleteContext dataclass #

AutocompleteContext(
    interaction: PartialInteraction,
    app: GatewayTraits | RESTTraits,
    client: Client,
    application_id: Snowflake,
    type: int,
    token: str,
    id: Snowflake,
    version: int,
    channel_id: Snowflake,
    guild_id: Snowflake | None,
    registered_guild_id: Snowflake | None,
    user: User,
    member: Member | None,
    entitlements: Sequence[hikari.Entitlement],
    locale: Locale,
    command: str,
    command_type: hikari.CommandType,
    group: str | None,
    sub_group: str | None,
    options: dict[str, Any],
    _has_created_response: bool,
    _has_deferred_response: bool,
    _rest_interaction_future: Future[
        InteractionResponseBuilder
    ]
    | None,
)

Bases: InteractionContext

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.

entitlements instance-attribute #

entitlements: Sequence[hikari.Entitlement]

For monetized apps, any entitlements involving this user. Represents access to SKUs.

guild_id instance-attribute #

guild_id: Snowflake | None

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

id instance-attribute #

The ID of the interaction.

interaction instance-attribute #

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.

registered_guild_id instance-attribute #

registered_guild_id: Snowflake | None

The guild ID of the guild that this command is registered to.

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 dataclass #

Context(
    interaction: PartialInteraction,
    app: GatewayTraits | RESTTraits,
    client: Client,
    application_id: Snowflake,
    type: int,
    token: str,
    id: Snowflake,
    version: int,
    channel_id: Snowflake,
    guild_id: Snowflake | None,
    registered_guild_id: Snowflake | None,
    user: User,
    member: Member | None,
    entitlements: Sequence[hikari.Entitlement],
    locale: Locale,
    command: str,
    command_type: hikari.CommandType,
    group: str | None,
    sub_group: str | None,
    options: dict[str, Any],
    _has_created_response: bool,
    _has_deferred_response: bool,
    _rest_interaction_future: Future[
        InteractionResponseBuilder
    ]
    | None,
)

Bases: InteractionContext

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 #

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.

entitlements instance-attribute #

entitlements: Sequence[hikari.Entitlement]

For monetized apps, any entitlements involving this user. Represents access to SKUs.

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 #

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.

registered_guild_id instance-attribute #

registered_guild_id: Snowflake | None

The guild ID of the guild that this command is registered to.

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

ephemeral

Send this message as ephemeral if set to true. Ephemeral messages can be dismissed by the user, similar to Clyde messages. This kwarg only affects the initial response to an interaction.

TYPE: bool DEFAULT: False

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 ephemeral 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.

InteractionContext dataclass #

InteractionContext(
    interaction: PartialInteraction,
    app: GatewayTraits | RESTTraits,
    client: Client,
    application_id: Snowflake,
    type: int,
    token: str,
    id: Snowflake,
    version: int,
    channel_id: Snowflake,
    guild_id: Snowflake | None,
    registered_guild_id: Snowflake | None,
    user: User,
    member: Member | None,
    entitlements: Sequence[hikari.Entitlement],
    locale: Locale,
    command: str,
    command_type: hikari.CommandType,
    group: str | None,
    sub_group: str | None,
    options: dict[str, Any],
    _has_created_response: bool,
    _has_deferred_response: bool,
    _rest_interaction_future: Future[
        InteractionResponseBuilder
    ]
    | None,
)

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.

entitlements instance-attribute #

entitlements: Sequence[hikari.Entitlement]

For monetized apps, any entitlements involving this user. Represents access to SKUs.

guild_id instance-attribute #

guild_id: Snowflake | None

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

id instance-attribute #

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.

registered_guild_id instance-attribute #

registered_guild_id: Snowflake | None

The guild ID of the guild that this command is registered to.

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.