discord-interactions.py

Attachment

Function

Attachment option. file_types filters on Discord's side, allowed_extensions and max_size on the bot's side.

from discord_interactions import Attachment

Signature

def Attachment(    name: str,    description: str,    *,    required: bool = True,    allowed_extensions: List[str] | None = None,    max_size: int | None = None,    file_types: List[str] | None = None,    localizations: Dict[str, Tuple[str, str]] | None = None,) -> AttachmentOption

Parameters

NameTypeDefaultDescription
namestrrequired
descriptionstrrequired
requiredboolTrue
allowed_extensionsList[str] | NoneNoneAccepted extensions, checked by the bot.
max_sizeint | NoneNoneMaximum size in bytes.
file_typesList[str] | NoneNoneTypes offered by Discord: "image", "video", "audio" or extensions.
localizationsDict[str, Tuple[str, str]] | NoneNone

Returns

AttachmentOption

Example

from discord_interactions.slash import Attachment, option @slash.command(description="Analyser une image")@option(Attachment("image", "Image", file_types=["image"], max_size=8_000_000))async def analyser(ctx, image):    await ctx.respond(f"{image.filename} : {image.width}×{image.height}")

Type a name: create_button, ModalBuilder, cooldown.