discord-interactions.py

Modern Discord components, written in Python.

Components V2, modals and slash commands for discord.py. You write the message, the module talks to the Discord API directly.

Read the documentation
Code and how it renders in Discord. Hover a line to see what it produces.
@slash.command(description="Server status")async def statut(ctx):    carte = (        container(accent_color=0x5865F2)        .add(section("## Minecraft server", "12 players online").thumbnail(LOGO))        .separator()        .add("Next restart in **2 h**")        .row(            create_button("rejoindre", "Join", style="success"),            create_button("joueurs", "Show players"),        )    )    await ctx.respond(components=[carte])

A card, not an embed.

Markdown text, thumbnails, galleries, attached files and buttons, in the order you choose. The Components V2 flag and text conversion are handled for you.

  • Chainable builders or functions returning the API JSON
  • Update a single button in a message already sent
  • Data embedded in the custom_id, signed when needed
from discord_interactions import update_component @router.on("rejoindre")async def rejoindre(interaction, data):    await defer_interaction(interaction, update=True)    await update_component(        interaction.message,        "rejoindre",        {"disabled": True, "label": "Joined"},    )

Complete forms.

Radio buttons, checkboxes, user or channel menus, file uploads: every Discord modal field, with values read as discord.py objects.

modale = (    ModalBuilder("signalement", "Report an issue")    .text_input("sujet", "Subject", max_length=80)    .radio("gravite", "Severity", ["Low", "Blocking"])    .checkboxes("zones", "Affected areas", ["Bot", "Website"])    .file_upload("captures", "Screenshots", file_types=["image"], required=False))await ctx.send_modal(modale)

Typed slash commands.

Options validated before your code runs, members, roles and files received as objects, autocomplete, cooldowns and permissions as decorators.

@slash.command(description="Weather")@option(String("city", "City to show", autocomplete=from_list(VILLES)))@cooldown(1, 10)async def weather(ctx, city):    await ctx.respond(f"{city} : 18 °C")

At a glance

Dependency
discord.py 2.6, nothing else
Python
3.9 to 3.14
Discord API
Every component, from buttons to FileUpload
Documentation
French and English, one version per release
License
MIT

Your first bot fits in thirty lines.

The getting started guide takes you from install to the first clicked button.

Read the documentation