discord-interactions.py

SlashContext

Class

Command context: interaction, author, channel, options and response methods.

from discord_interactions import SlashContext

Constructor

SlashContext(    interaction: discord.Interaction,    command: SlashCommand | None = None,    options: Dict[str, Any] | None = None,)
NameTypeDefaultDescription
interactiondiscord.Interactionrequired
commandSlashCommand | NoneNone
optionsDict[str, Any] | NoneNone

Properties

NameTypeDescription
interactiondiscord.Interaction
userdiscord.User | discord.Member
authordiscord.User | discord.Member
memberdiscord.Member | None
guilddiscord.Guild | None
channel
channel_idint | None
guild_idint | None
localestr
guild_localestr | None
botdiscord.Client
clientdiscord.Client
commandSlashCommand | None
command_namestr
optionsDict[str, Any]
respondedbool
deferredbool
permissionsdiscord.Permissions
app_permissionsdiscord.Permissions

Methods

get

def get(name: str, default: Any = None) -> Any

Value of an option, or default.

respond

async def respond(    content: str | None = None,    *,    embed: discord.Embed | None = None,    embeds: List[discord.Embed] | None = None,    components: Sequence[Any] | None = None,    ephemeral: bool | None = None,    flags: int | None = None,    tts: bool = False,    files: Sequence[discord.File] | None = None,    file: discord.File | None = None,    allowed_mentions: Any | None = None,) -> Dict[str, Any] | None

Initial response, or an automatic followup when a response or defer already exists.

followup

async def followup(content: str | None = None, **kwargs: Any) -> Dict[str, Any]

Sends a followup message.

defer

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

Shows the thinking state to answer later.

edit

async def edit(    content: str | None = None,    *,    embed: discord.Embed | None = None,    embeds: List[discord.Embed] | None = None,    components: Sequence[Any] | None = None,    files: Sequence[discord.File] | None = None,    attachments: Sequence[Any] | None = None,    allowed_mentions: Any | None = None,) -> Dict[str, Any]

Edits the original response.

delete

async def delete() -> None

Deletes the original response.

send_modal

async def send_modal(    custom_id: Any,    title: str | None = None,    components: List[Any] | None = None,) -> None

Opens a modal.

reply

async def reply(content: str | None = None, **kwargs: Any) -> Dict[str, Any] | None

send

async def send(content: str | None = None, **kwargs: Any) -> Dict[str, Any] | None

think

async def think(ephemeral: bool = False) -> None

set_ephemeral_default

def set_ephemeral_default(value: bool) -> None

Example

@slash.command(description="Traitement long")async def rapport(ctx):    await ctx.defer(ephemeral=True)    await ctx.respond("Rapport prêt")    await ctx.edit("Rapport prêt et envoyé")

Type a name: create_button, ModalBuilder, cooldown.