Skip to content

decorators

Dynamic Permission Decorators.

This module provides fully dynamic, database-driven permission decorators that have NO hardcoded opinions about permission ranks or names.

Architecture: ALL commands use @requires_command_permission() with NO arguments. The required permission rank is stored in the database per-guild. Guilds MUST configure permissions before commands work (safe default).

Recommended Usage: @requires_command_permission() # 100% dynamic, reads from database async def ban(self, ctx, user): ...

Configuration: Admins use /config permission command ban rank:3 to set requirements. Without configuration, commands are DENIED by default (safe mode).

Functions:

Classes

Functions

requires_command_permission

Python
requires_command_permission(*, allow_unconfigured: bool = False) -> Callable[[F], F]

Provide dynamic, database-driven command permissions.

This decorator provides fully dynamic permission checking that reads required permission ranks from the database per guild. Commands are denied by default if not configured (safe mode).

Parameters:

  • allow_unconfigured (bool, default: False ) –

    If True, allow commands without database configuration. If False (default), deny unconfigured commands.

Returns:

  • Callable[[F], F]

    The decorated function with permission checking.

_get_user_rank_from_interaction async

Python
_get_user_rank_from_interaction(
    permission_system: Any, interaction: Interaction[Any]
) -> int

Get user permission rank from an interaction (for app commands).

Uses Discord.py's built-in Context.from_interaction() to create a proper context.

Parameters:

  • permission_system (Any) –

    The permission system to use.

  • interaction (Interaction[Any]) –

    The interaction to get the user permission rank from.

Returns:

  • int

    The user permission rank.

_extract_context_or_interaction

Python
_extract_context_or_interaction(
    args: tuple[Any, ...],
) -> tuple[Context[Any] | None, Interaction[Any] | None]

Extract Discord context or interaction from function arguments.

Returns:

  • Tuple of (context, interaction) - one will be None, the other populated