Permissions¶
This section documents everything related to permissions - a way of granting (or limiting) certain entities access to certain information/actions.
Data Classes¶
Permissions¶
- clsPermissions.advanced
- clsPermissions.all
- clsPermissions.all_channel
- clsPermissions.apps
- clsPermissions.events
- clsPermissions.general
- clsPermissions.membership
- clsPermissions.none
- clsPermissions.private_channel
- clsPermissions.stage
- clsPermissions.stage_moderator
- clsPermissions.text
- clsPermissions.voice
- defis_strict_subset
- defis_strict_superset
- defis_subset
- defis_superset
- defupdate
- 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)andPermissions(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
Permissionssimilar toupdate().- 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
yinverted 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:
- is_strict_subset(other)[source]¶
Returns
Trueif the permissions on self are a strict subset of those on other.
- is_strict_superset(other)[source]¶
Returns
Trueif the permissions on self are a strict superset of those on other.
- classmethod none()[source]¶
A factory method that creates a
Permissionswith all permissions set toFalse.
- classmethod all()[source]¶
A factory method that creates a
Permissionswith all permissions set toTrue.
- classmethod all_channel()[source]¶
A
Permissionswith all channel-specific permissions set toTrueand the guild-specific ones set toFalse. The guild-specific permissions are currently:create_guild_expressionsmanage_guild_expressionsview_audit_logview_guild_insightsview_creator_monetization_analyticsmanage_guildchange_nicknamemanage_nicknameskick_membersban_membersmoderate_membersadministrator
Changed in version 1.7: Added
stream,priority_speakeranduse_slash_commandspermissions.Changed in version 2.0: Added
create_public_threads,create_private_threads,manage_threads,use_external_stickers,send_messages_in_threadsandrequest_to_speakpermissions.Changed in version 2.3: Added
use_embedded_activitiespermission.Changed in version 2.9: Added
use_soundboardandsend_voice_messagespermissions.Changed in version 2.10: Added
create_eventspermission.
- classmethod general()[source]¶
A factory method that creates a
Permissionswith all “General” permissions from the official Discord UI set toTrue.Changed in version 1.7: Permission
read_messagesis now included in the general permissions, but permissionsadministrator,create_instant_invite,kick_members,ban_members,change_nicknameandmanage_nicknamesare no longer part of the general permissions.Changed in version 2.9: Added
view_creator_monetization_analyticspermission.Changed in version 2.10: Added
create_guild_expressionspermission.
- classmethod membership()[source]¶
A factory method that creates a
Permissionswith all “Membership” permissions from the official Discord UI set toTrue.New in version 1.7.
Changed in version 2.3: Added
moderate_memberspermission.
- classmethod text()[source]¶
A factory method that creates a
Permissionswith all “Text” permissions from the official Discord UI set toTrue.Changed in version 1.7: Permission
read_messagesis no longer part of the text permissions. Addeduse_slash_commandspermission.Changed in version 2.0: Added
create_public_threads,create_private_threads,manage_threads,send_messages_in_threadsanduse_external_stickerspermissions.Changed in version 2.9: Added
send_voice_messagespermission.Changed in version 2.10: Moved
use_application_commandspermission toapps.Changed in version 2.11: Added
pin_messagespermission.
- classmethod voice()[source]¶
A factory method that creates a
Permissionswith all “Voice” permissions from the official Discord UI set toTrue.Changed in version 2.3: Added
use_embedded_activitiespermission.Changed in version 2.9: Added
use_soundboardanduse_external_soundspermissions.Changed in version 2.10: Moved
use_embedded_activitiespermission toapps.
- classmethod stage()[source]¶
A factory method that creates a
Permissionswith all “Stage Channel” permissions from the official Discord UI set toTrue.New in version 1.7.
- classmethod stage_moderator()[source]¶
A factory method that creates a
Permissionswith all “Stage Moderator” permissions from the official Discord UI set toTrue.New in version 1.7.
- classmethod apps()[source]¶
A factory method that creates a
Permissionswith all “Apps” permissions from the official Discord UI set toTrue.New in version 2.10.
- classmethod events()[source]¶
A factory method that creates a
Permissionswith all “Events” permissions from the official Discord UI set toTrue.New in version 2.4.
Changed in version 2.10: Added
create_eventspermission.
- classmethod advanced()[source]¶
A factory method that creates a
Permissionswith all “Advanced” permissions from the official Discord UI set toTrue.New in version 1.7.
- classmethod private_channel()[source]¶
A factory method that creates a
Permissionswith the best representation of a PrivateChannel’s permissions.This exists to maintain compatibility with other channel types.
This is equivalent to
Permissions.text()withview_channelwith 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¶
- clsPermissionOverwrite.from_pair
- defis_empty
- defpair
- defupdate
- 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 toNoneand notFalse. Setting a value toFalseis explicitly denying that permission, while setting a value toTrueis explicitly allowing that permission.The values supported by this are the same as
Permissionswith the added possibility of it being set toNone.- 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
TrueorFalse.- Returns:
Indicates if the overwrite is empty.
- Return type:
- 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.