Permissions

This section documents everything related to permissions - a way of granting (or limiting) certain entities access to certain information/actions.

Data Classes

Permissions

class disnake.Permissions(permissions=0, **kwargs)[source]

Wraps up the Discord permission value.

The properties provided are two way. You can set and retrieve individual bits using the properties as if they were regular bools. This allows you to edit permissions.

To construct an object you can pass keyword arguments denoting the permissions to enable or disable. Arguments are applied in order, which notably also means that supplying a flag and its alias will make whatever comes last overwrite the first one; as an example, Permissions(external_emojis=True, use_external_emojis=False) and Permissions(use_external_emojis=True, external_emojis=False) both result in the same permissions value (0).

Changed in version 1.3: You can now use keyword arguments to initialize Permissions similar to update().

x == y

Checks if two permissions are equal.

x != y

Checks if two permissions are not equal.

x <= y

Checks if a permission is a subset of another permission.

x >= y

Checks if a permission is a superset of another permission.

x < y

Checks if a permission is a strict subset of another permission.

x > y

Checks if a permission is a strict superset of another permission.

x | y, x |= y

Returns a new Permissions instance with all enabled permissions from both x and y. (Using |= will update in place).

New in version 2.6.

x & y, x &= y

Returns a new Permissions instance with only permissions enabled on both x and y. (Using &= will update in place).

New in version 2.6.

x ^ y, x ^= y

Returns a new Permissions instance with only permissions enabled on one of x or y, but not both. (Using ^= will update in place).

New in version 2.6.

~x

Returns a new Permissions instance with all permissions from x inverted.

New in version 2.6.

hash(x)

Return the permission’s hash.

iter(x)

Returns an iterator of (perm, value) pairs. This allows it to be, for example, constructed as a dict or a list of pairs. Note that aliases are not shown.

Additionally supported are a few operations on class attributes.

Permissions.y | Permissions.z, Permissions(y=True) | Permissions.z

Returns a Permissions instance with all provided permissions enabled.

New in version 2.6.

~Permissions.y

Returns a Permissions instance with all permissions except y inverted from their default value.

New in version 2.6.

value

The raw value. This value is a bit array field of a 53-bit integer representing the currently available permissions. You should query permissions via the properties rather than using this raw value.

Type:

int

is_subset(other)[source]

Returns True if self has the same or fewer permissions as other.

is_superset(other)[source]

Returns True if self has the same or more permissions as other.

is_strict_subset(other)[source]

Returns True if the permissions on self are a strict subset of those on other.

is_strict_superset(other)[source]

Returns True if the permissions on self are a strict superset of those on other.

classmethod none()[source]

A factory method that creates a Permissions with all permissions set to False.

classmethod all()[source]

A factory method that creates a Permissions with all permissions set to True.

classmethod all_channel()[source]

A Permissions with all channel-specific permissions set to True and the guild-specific ones set to False. The guild-specific permissions are currently:

  • create_guild_expressions

  • manage_guild_expressions

  • view_audit_log

  • view_guild_insights

  • view_creator_monetization_analytics

  • manage_guild

  • change_nickname

  • manage_nicknames

  • kick_members

  • ban_members

  • moderate_members

  • administrator

Changed in version 1.7: Added stream, priority_speaker and use_slash_commands permissions.

Changed in version 2.0: Added create_public_threads, create_private_threads, manage_threads, use_external_stickers, send_messages_in_threads and request_to_speak permissions.

Changed in version 2.3: Added use_embedded_activities permission.

Changed in version 2.9: Added use_soundboard and send_voice_messages permissions.

Changed in version 2.10: Added create_events permission.

classmethod general()[source]

A factory method that creates a Permissions with all “General” permissions from the official Discord UI set to True.

Changed in version 1.7: Permission read_messages is now included in the general permissions, but permissions administrator, create_instant_invite, kick_members, ban_members, change_nickname and manage_nicknames are no longer part of the general permissions.

Changed in version 2.9: Added view_creator_monetization_analytics permission.

Changed in version 2.10: Added create_guild_expressions permission.

classmethod membership()[source]

A factory method that creates a Permissions with all “Membership” permissions from the official Discord UI set to True.

New in version 1.7.

Changed in version 2.3: Added moderate_members permission.

classmethod text()[source]

A factory method that creates a Permissions with all “Text” permissions from the official Discord UI set to True.

Changed in version 1.7: Permission read_messages is no longer part of the text permissions. Added use_slash_commands permission.

Changed in version 2.0: Added create_public_threads, create_private_threads, manage_threads, send_messages_in_threads and use_external_stickers permissions.

Changed in version 2.9: Added send_voice_messages permission.

Changed in version 2.10: Moved use_application_commands permission to apps.

Changed in version 2.11: Added pin_messages permission.

classmethod voice()[source]

A factory method that creates a Permissions with all “Voice” permissions from the official Discord UI set to True.

Changed in version 2.3: Added use_embedded_activities permission.

Changed in version 2.9: Added use_soundboard and use_external_sounds permissions.

Changed in version 2.10: Moved use_embedded_activities permission to apps.

classmethod stage()[source]

A factory method that creates a Permissions with all “Stage Channel” permissions from the official Discord UI set to True.

New in version 1.7.

classmethod stage_moderator()[source]

A factory method that creates a Permissions with all “Stage Moderator” permissions from the official Discord UI set to True.

New in version 1.7.

classmethod apps()[source]

A factory method that creates a Permissions with all “Apps” permissions from the official Discord UI set to True.

New in version 2.10.

classmethod events()[source]

A factory method that creates a Permissions with all “Events” permissions from the official Discord UI set to True.

New in version 2.4.

Changed in version 2.10: Added create_events permission.

classmethod advanced()[source]

A factory method that creates a Permissions with all “Advanced” permissions from the official Discord UI set to True.

New in version 1.7.

classmethod private_channel()[source]

A factory method that creates a Permissions with the best representation of a PrivateChannel’s permissions.

This exists to maintain compatibility with other channel types.

This is equivalent to Permissions.text() with view_channel with the following set to False:

  • send_tts_messages: You cannot send TTS messages in a DM.

  • manage_messages: You cannot delete others messages in a DM.

  • manage_threads: You cannot manage threads in a DM.

  • send_messages_in_threads: You cannot make threads in a DM.

  • create_public_threads: You cannot make public threads in a DM.

  • create_private_threads: You cannot make private threads in a DM.

New in version 2.4.

update(**kwargs)[source]

Bulk updates this permission object.

Allows you to set multiple attributes by using keyword arguments. The names must be equivalent to the properties listed. Extraneous key/value pairs will be silently ignored.

Arguments are applied in order, similar to the constructor.

Parameters:

**kwargs – A list of key/value pairs to bulk update permissions with.

PermissionOverwrite

class disnake.PermissionOverwrite(**kwargs)[source]

A type that is used to represent a channel specific permission.

Unlike a regular Permissions, the default value of a permission is equivalent to None and not False. Setting a value to False is explicitly denying that permission, while setting a value to True is explicitly allowing that permission.

The values supported by this are the same as Permissions with the added possibility of it being set to None.

x == y

Checks if two overwrites are equal.

x != y

Checks if two overwrites are not equal.

iter(x)

Returns an iterator of (perm, value) pairs. This allows it to be, for example, constructed as a dict or a list of pairs. Note that aliases are not shown.

Parameters:

**kwargs – Set the value of permissions by their name.

pair()[source]

tuple[Permissions, Permissions]: Returns the (allow, deny) pair from this overwrite.

classmethod from_pair(allow, deny)[source]

Creates an overwrite from an allow/deny pair of Permissions.

is_empty()[source]

Checks if the permission overwrite is currently empty.

An empty permission overwrite is one that has no overwrites set to True or False.

Returns:

Indicates if the overwrite is empty.

Return type:

bool

update(**kwargs)[source]

Bulk updates this permission overwrite object.

Allows you to set multiple attributes by using keyword arguments. The names must be equivalent to the properties listed. Extraneous key/value pairs will be silently ignored.

Parameters:

**kwargs – A list of key/value pairs to bulk update with.