disagreement/docs/permissions.md
Slipstream a222dec661
Some checks failed
Deploy MkDocs / deploy (push) Has been cancelled
Add Permissions.all convenience (#107)
2025-06-15 18:49:43 -06:00

1.5 KiB

Permission Helpers

The disagreement.permissions module defines an :class:~enum.IntFlag Permissions enumeration along with helper functions for working with the Discord permission bitmask.

Permissions Enum

Each attribute of Permissions represents a single permission bit. The value is a power of two so multiple permissions can be combined using bitwise OR.

from disagreement import Permissions

value = Permissions.SEND_MESSAGES | Permissions.MANAGE_MESSAGES

You can also get a bitmask containing every permission:

all_perms = Permissions.all()

Helper Functions

permissions_value

permissions_value(*perms) -> int

Return an integer bitmask from one or more Permissions values. Nested iterables are flattened automatically.

has_permissions

has_permissions(current, *perms) -> bool

Return True if current (an int or Permissions) contains all of the provided permissions.

missing_permissions

missing_permissions(current, *perms) -> List[Permissions]

Return a list of permissions that current does not contain.

Example

from disagreement.permissions import (
    has_permissions,
    missing_permissions,
)
from disagreement import Permissions

current = Permissions.SEND_MESSAGES | Permissions.MANAGE_MESSAGES

if has_permissions(current, Permissions.SEND_MESSAGES):
    print("Can send messages")

print(missing_permissions(current, Permissions.ADMINISTRATOR))