Перейти к содержанию

Контексты взаимодействий

Как ими пользоваться, объясняет руководство «Ответы на взаимодействия».

bostie.Context

Context(interaction: I, bot: Bot, *, received: float, ephemeral: bool, allowed_mentions: AllowedMentions, deletions: set[Task[None]])

Bases: _ReplyingContext[CommandInteraction, WebhookMessage]

The context of a command run: who ran it, where, and how to answer.

interaction instance-attribute

interaction = interaction

bot instance-attribute

bot = bot

user property

user: User

The user who triggered the interaction, in a guild or in a DM.

member property

member: Member | None

guild_id property

guild_id: int | None

channel_id property

channel_id: int | None

channel property

channel: PartialChannel | None

locale property

locale: Locale

voice property

voice: ContextVoice

Voice in this guild; connect() joins the channel of the user who ran it.

command_name property

command_name: str

The invoked command with its subcommands, such as "role color set".

typing

typing() -> Typing

Typing in the interaction's channel, awaited once or kept in async with.

respond async

respond(content: str | None = None, *, delete_after: float | None = None, **parts: Unpack[ReplyParts]) -> WebhookMessage

Answer, fill in the deferred answer, or send a follow-up, whichever fits.

delete_after deletes that message so many seconds later, within 15 minutes.

defer async

defer(*, ephemeral: bool | None = None) -> None

Show "thinking…" and answer later with respond.

edit async

edit(**parts: Unpack[ReplyEditParts]) -> M
edit(message_id: int, /, **parts: Unpack[ReplyEditParts]) -> WebhookMessage
edit(message_id: int | None = None, /, **parts: Unpack[ReplyEditParts]) -> M | WebhookMessage

Edit the original answer, or the follow-up message_id.

A part not given stays and None clears it. With files or attachments, only the listed attachments stay.

fetch async

fetch() -> M
fetch(message_id: int) -> WebhookMessage
fetch(message_id: int | None = None) -> M | WebhookMessage

The original answer as Discord has it now, or the follow-up message_id.

followup async

followup(content: str | None = None, *, delete_after: float | None = None, **parts: Unpack[ReplyParts]) -> WebhookMessage

Send another message, or fill in the answer right after defer().

delete async

delete(message_id: int | None = None) -> None

Delete the original answer, or the follow-up message_id.

launch_activity async

launch_activity() -> str

Open the app's Activity for the user; return the id of its instance.

modal async

modal(modal: ModalDict) -> None

Answer with a modal built by ui.modal; nothing can answer after it.

bostie.ComponentContext

ComponentContext(interaction: I, bot: Bot, *, received: float, ephemeral: bool, allowed_mentions: AllowedMentions, deletions: set[Task[None]])

Bases: _UpdatingContext[ComponentInteraction]

The context of a button or select menu use.

interaction instance-attribute

interaction = interaction

bot instance-attribute

bot = bot

user property

user: User

The user who triggered the interaction, in a guild or in a DM.

member property

member: Member | None

guild_id property

guild_id: int | None

channel_id property

channel_id: int | None

channel property

channel: PartialChannel | None

locale property

locale: Locale

voice property

voice: ContextVoice

Voice in this guild; connect() joins the channel of the user who ran it.

custom_id property

custom_id: str

values property

values: tuple[str, ...]

The options picked in a string select.

ids property

ids: tuple[int, ...]

The ids of the users, roles or channels picked in a select.

users property

users: tuple[User, ...]

The users picked in a user or mentionable select.

members property

members: tuple[ResolvedMember, ...]

The members picked in a user or mentionable select in a guild.

roles property

roles: tuple[Role, ...]

The roles picked in a role or mentionable select.

channels property

channels: tuple[PartialChannel, ...]

The channels picked in a channel select.

typing

typing() -> Typing

Typing in the interaction's channel, awaited once or kept in async with.

respond async

respond(content: str | None = None, *, delete_after: float | None = None, **parts: Unpack[ReplyParts]) -> WebhookMessage

Answer, fill in the deferred answer, or send a follow-up, whichever fits.

delete_after deletes that message so many seconds later, within 15 minutes.

defer async

defer(*, ephemeral: bool | None = None) -> None

Show "thinking…" and answer later with respond.

edit async

edit(**parts: Unpack[ReplyEditParts]) -> M
edit(message_id: int, /, **parts: Unpack[ReplyEditParts]) -> WebhookMessage
edit(message_id: int | None = None, /, **parts: Unpack[ReplyEditParts]) -> M | WebhookMessage

Edit the original answer, or the follow-up message_id.

A part not given stays and None clears it. With files or attachments, only the listed attachments stay.

fetch async

fetch() -> M
fetch(message_id: int) -> WebhookMessage
fetch(message_id: int | None = None) -> M | WebhookMessage

The original answer as Discord has it now, or the follow-up message_id.

followup async

followup(content: str | None = None, *, delete_after: float | None = None, **parts: Unpack[ReplyParts]) -> WebhookMessage

Send another message, or fill in the answer right after defer().

delete async

delete(message_id: int | None = None) -> None

Delete the original answer, or the follow-up message_id.

launch_activity async

launch_activity() -> str

Open the app's Activity for the user; return the id of its instance.

defer_update async

defer_update() -> None

Acknowledge silently; edit the component's message later with update.

update async

Edit the component's message: a part not given stays and None clears it.

With files or attachments, only the listed attachments stay.

modal async

modal(modal: ModalDict) -> None

Answer with a modal built by ui.modal; nothing can answer after it.

bostie.ModalContext

ModalContext(interaction: I, bot: Bot, *, received: float, ephemeral: bool, allowed_mentions: AllowedMentions, deletions: set[Task[None]])

Bases: _UpdatingContext[ModalSubmitInteraction]

The context of a modal submit; update edits the message that opened it.

interaction instance-attribute

interaction = interaction

bot instance-attribute

bot = bot

user property

user: User

The user who triggered the interaction, in a guild or in a DM.

member property

member: Member | None

guild_id property

guild_id: int | None

channel_id property

channel_id: int | None

channel property

channel: PartialChannel | None

locale property

locale: Locale

voice property

voice: ContextVoice

Voice in this guild; connect() joins the channel of the user who ran it.

custom_id property

custom_id: str

typing

typing() -> Typing

Typing in the interaction's channel, awaited once or kept in async with.

respond async

respond(content: str | None = None, *, delete_after: float | None = None, **parts: Unpack[ReplyParts]) -> WebhookMessage

Answer, fill in the deferred answer, or send a follow-up, whichever fits.

delete_after deletes that message so many seconds later, within 15 minutes.

defer async

defer(*, ephemeral: bool | None = None) -> None

Show "thinking…" and answer later with respond.

edit async

edit(**parts: Unpack[ReplyEditParts]) -> M
edit(message_id: int, /, **parts: Unpack[ReplyEditParts]) -> WebhookMessage
edit(message_id: int | None = None, /, **parts: Unpack[ReplyEditParts]) -> M | WebhookMessage

Edit the original answer, or the follow-up message_id.

A part not given stays and None clears it. With files or attachments, only the listed attachments stay.

fetch async

fetch() -> M
fetch(message_id: int) -> WebhookMessage
fetch(message_id: int | None = None) -> M | WebhookMessage

The original answer as Discord has it now, or the follow-up message_id.

followup async

followup(content: str | None = None, *, delete_after: float | None = None, **parts: Unpack[ReplyParts]) -> WebhookMessage

Send another message, or fill in the answer right after defer().

delete async

delete(message_id: int | None = None) -> None

Delete the original answer, or the follow-up message_id.

launch_activity async

launch_activity() -> str

Open the app's Activity for the user; return the id of its instance.

defer_update async

defer_update() -> None

Acknowledge silently; edit the component's message later with update.

update async

Edit the component's message: a part not given stays and None clears it.

With files or attachments, only the listed attachments stay.

text

text(custom_id: str) -> str

What the user typed in the text input custom_id.

values

values(custom_id: str) -> tuple[str, ...]

The options picked in the string select or checkbox group custom_id.

ids

ids(custom_id: str) -> tuple[int, ...]

The ids of the users, roles, channels or files picked in custom_id.

users

users(custom_id: str) -> tuple[User, ...]

The users picked in the user or mentionable select custom_id.

members

members(custom_id: str) -> tuple[ResolvedMember, ...]

The members picked in the user or mentionable select custom_id.

roles

roles(custom_id: str) -> tuple[Role, ...]

The roles picked in the role or mentionable select custom_id.

channels

channels(custom_id: str) -> tuple[PartialChannel, ...]

The channels picked in the channel select custom_id.

attachments

attachments(custom_id: str) -> tuple[Attachment, ...]

The files uploaded with the file upload custom_id.

choice

choice(custom_id: str) -> str | None

The option picked in the radio group custom_id, if any.

checked

checked(custom_id: str) -> bool

Whether the checkbox custom_id is ticked.

bostie.AutocompleteContext

AutocompleteContext(interaction: I, bot: Bot, *, received: float)

Bases: _InteractionContext[AutocompleteInteraction]

The context of an autocomplete request; it never defers.

interaction instance-attribute

interaction = interaction

bot instance-attribute

bot = bot

user property

user: User

The user who triggered the interaction, in a guild or in a DM.

member property

member: Member | None

guild_id property

guild_id: int | None

channel_id property

channel_id: int | None

channel property

channel: PartialChannel | None

locale property

locale: Locale

voice property

voice: ContextVoice

Voice in this guild; connect() joins the channel of the user who ran it.

command_name property

command_name: str

The command being filled in, with its subcommands.

options property

options: dict[str, Any]

The options filled so far by name, as the handler gets them if they convert.

Required ones may be missing, and the focused one is the text typed so far.

respond async

respond(choices: list[dict[str, Any]]) -> None

Answer with these Discord choice objects; autocomplete results go here.

Части сообщения

bostie.context.ReplyParts

Bases: MessageParts

The parts of an answer; without ephemeral, the command's setting applies.

ephemeral instance-attribute

ephemeral: bool

embeds instance-attribute

embeds: Sequence[Embed | Mapping[str, Any]]

components instance-attribute

components: Sequence[Component | Mapping[str, Any]]

files instance-attribute

files: Sequence[File]

allowed_mentions instance-attribute

allowed_mentions: AllowedMentions

flags instance-attribute

flags: MessageFlags

tts instance-attribute

tts: bool

poll instance-attribute

bostie.context.ReplyEditParts

Bases: EditParts

The parts of an edit; ephemeral cannot change a sent message and only warns.

ephemeral instance-attribute

ephemeral: bool

content instance-attribute

content: str | None

embeds instance-attribute

embeds: Sequence[Embed | Mapping[str, Any]] | None

components instance-attribute

components: Sequence[Component | Mapping[str, Any]] | None

files instance-attribute

files: Sequence[File]

allowed_mentions instance-attribute

allowed_mentions: AllowedMentions | None

flags instance-attribute

flags: MessageFlags | None

attachments instance-attribute

attachments: Sequence[Attachment | int] | None

bostie.models.message.MessageParts

Bases: TypedDict

The parts of a message to send; a part not given is left out.

embeds instance-attribute

embeds: Sequence[Embed | Mapping[str, Any]]

components instance-attribute

components: Sequence[Component | Mapping[str, Any]]

files instance-attribute

files: Sequence[File]

allowed_mentions instance-attribute

allowed_mentions: AllowedMentions

flags instance-attribute

flags: MessageFlags

tts instance-attribute

tts: bool

poll instance-attribute

bostie.models.message.EditParts

Bases: TypedDict

The parts of a message to edit: a part not given stays and None clears it.

With files or attachments, only the listed attachments stay.

content instance-attribute

content: str | None

embeds instance-attribute

embeds: Sequence[Embed | Mapping[str, Any]] | None

components instance-attribute

components: Sequence[Component | Mapping[str, Any]] | None

files instance-attribute

files: Sequence[File]

allowed_mentions instance-attribute

allowed_mentions: AllowedMentions | None

flags instance-attribute

flags: MessageFlags | None

attachments instance-attribute

attachments: Sequence[Attachment | int] | None