discord-interactions.py

Middleware

Class

Before, after and error hooks, filterable per command.

from discord_interactions.slash import Middleware

Constructor

Middleware(    name: str,    before: Callable[[SlashContext], Awaitable[bool | None]] | None = None,    after: Callable[[SlashContext, Any, Exception | None], Awaitable[None]] | None = None,    on_error: Callable[[SlashContext, Exception], Awaitable[bool | None]] | None = None,    priority: int = 100,    commands: List[str] | None = None,    exclude_commands: List[str] | None = None,)
NameTypeDefaultDescription
namestrrequired
beforeCallable[[SlashContext], Awaitable[bool | None]] | NoneNone
afterCallable[[SlashContext, Any, Exception | None], Awaitable[None]] | NoneNone
on_errorCallable[[SlashContext, Exception], Awaitable[bool | None]] | NoneNone
priorityint100
commandsList[str] | NoneNone
exclude_commandsList[str] | NoneNone

Properties

NameTypeDescription
namestr
beforeCallable[[SlashContext], Awaitable[bool | None]] | None
afterCallable[[SlashContext, Any, Exception | None], Awaitable[None]] | None
on_errorCallable[[SlashContext, Exception], Awaitable[bool | None]] | None
priorityint
commandsList[str] | None
exclude_commandsList[str] | None

Methods

should_apply

def should_apply(command_name: str) -> bool

Check if this middleware should apply to a command.

Type a name: create_button, ModalBuilder, cooldown.