InteractionRouter
Classe
Route boutons, menus et modales vers des handlers selon le base_id de leur custom_id.
from discord_interactions import InteractionRouterAlias ButtonRouter
Constructeur
InteractionRouter()Méthodes
on
def on( base_id: str,) -> Callable[[Callable[..., Awaitable[Any]]], Callable[..., Awaitable[Any]]]Décorateur : handler pour un bouton ou un menu.
Alias button, select
modal
def modal( base_id: str,) -> Callable[[Callable[..., Awaitable[Any]]], Callable[..., Awaitable[Any]]]Décorateur : handler pour une modale ; reçoit un ModalSubmit.
fallback
def fallback(func: Callable[..., Awaitable[Any]]) -> Callable[..., Awaitable[Any]]Décorateur : handler des boutons et menus sans route dédiée.
handle
async def handle(interaction: discord.Interaction) -> boolTraite une interaction ; renvoie True si un handler l'a prise en charge.
Exemple
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)Détails
Le handler reçoit selon sa signature (interaction), (interaction, data)
ou (interaction, data, base_id). Pour une modale, data est un
ModalSubmit (valeurs + .data du custom_id).
router = InteractionRouter() @router.on("like")async def like(interaction, data): ... @router.modal("signalement")async def signalement(interaction, values): ... @client.eventasync def on_interaction(interaction): await router.handle(interaction)