discord-interactions.py

InteractionRouter

Class

Routes buttons, select menus and modals to handlers by the base_id of their custom_id.

from discord_interactions import InteractionRouter

Aliases ButtonRouter

Constructor

InteractionRouter()

Methods

on

def on(    base_id: str,) -> Callable[[Callable[..., Awaitable[Any]]], Callable[..., Awaitable[Any]]]

Decorator: handler for a button or a select menu.

Aliases button, select

modal

def modal(    base_id: str,) -> Callable[[Callable[..., Awaitable[Any]]], Callable[..., Awaitable[Any]]]

Decorator: handler for a modal; receives a ModalSubmit.

fallback

def fallback(func: Callable[..., Awaitable[Any]]) -> Callable[..., Awaitable[Any]]

Decorator: handler for buttons and menus without a dedicated route.

handle

async def handle(interaction: discord.Interaction) -> bool

Processes an interaction; returns True when a handler took it.

Example

from discord_interactions import InteractionRouter, update_message router = InteractionRouter() @router.on("vote")async def vote(interaction, data):    await update_message(interaction, content=f"Vote enregistré : {data['choix']}") @router.modal("profil")async def profil(interaction, valeurs):    ... @client.eventasync def on_interaction(interaction):    await router.handle(interaction)

Type a name: create_button, ModalBuilder, cooldown.