Permission bits
Permissions in a server are a 64-bit integer: each permission is one bit. A role holds a number, a bot is given a number when it is added to a server, and the permissions parameter of an install link is that number.
A member's permissions are the sum of the @everyone role and every role they hold. The owner of a server has all of them, and so does anyone with Administrator. In a channel, permissions are then adjusted by that channel's overwrites (first the category's, then the channel's own): a bit that an overwrite denies is taken away, one it allows is given. A member who cannot View channel can do nothing in it.
A permission marked channel can be allowed or denied for one channel; the others belong to the server as a whole.
Everyday
| Name | Bit | Value | Where | What it allows |
|---|---|---|---|---|
VIEW_CHANNEL | 0 | 1 | channel | See channels |
SEND_MESSAGES | 1 | 2 | channel | Send messages |
READ_HISTORY | 2 | 4 | channel | Read message history |
ADD_REACTIONS | 3 | 8 | channel | Add reactions |
MENTION_EVERYONE | 4 | 16 | channel | Mention @everyone |
MANAGE_MESSAGES | 5 | 32 | channel | Manage messages |
ATTACH_FILES | 31 | 2147483648 | channel | Attach files |
EMBED_GAMES | 32 | 4294967296 | channel | Embed games |
CREATE_INVITE | 16 | 65536 | channel | Create invites |
CHANGE_NICKNAME | 22 | 4194304 | server | Change its own nickname |
Voice
| Name | Bit | Value | Where | What it allows |
|---|---|---|---|---|
CONNECT | 8 | 256 | channel | Connect to voice |
SPEAK | 9 | 512 | channel | Speak in voice |
MUTE_MEMBERS | 10 | 1024 | channel | Mute members |
MOVE_MEMBERS | 11 | 2048 | channel | Move members |
STREAM | 33 | 8589934592 | channel | Go live |
STREAM_REACT | 34 | 17179869184 | channel | React over a stream |
Running the server
| Name | Bit | Value | Where | What it allows |
|---|---|---|---|---|
MANAGE_CHANNELS | 17 | 131072 | channel | Manage channels |
MANAGE_ROLES | 18 | 262144 | server | Manage roles |
MANAGE_SERVER | 19 | 524288 | server | Manage the server |
KICK_MEMBERS | 20 | 1048576 | server | Kick members |
BAN_MEMBERS | 21 | 2097152 | server | Ban members |
MANAGE_NICKNAMES | 23 | 8388608 | server | Manage nicknames |
MODERATE_MEMBERS | 24 | 16777216 | server | Put members in timeout |
ADMINISTRATOR | 30 | 1073741824 | server | Administrator (everything, in every channel) |
Rooms
| Name | Bit | Value | Where | What it allows |
|---|---|---|---|---|
CREATE_POSTS | 35 | 34359738368 | channel | Start forum posts |
MANAGE_POSTS | 36 | 68719476736 | channel | Manage forum posts |
TODO_ADD | 37 | 137438953472 | channel | Add to-do rows |
TODO_CHECK | 38 | 274877906944 | channel | Tick to-do rows |
TODO_EDIT | 39 | 549755813888 | channel | Edit others' to-do rows |
TODO_MANAGE | 40 | 1099511627776 | channel | Manage to-do lists |
DOC_EDIT | 41 | 2199023255552 | channel | Write in documents |
DOC_MANAGE | 42 | 4398046511104 | channel | Manage documents |
CREATE_POLLS | 43 | 8796093022208 | channel | Create polls |
CREATE_GIVEAWAYS | 44 | 17592186044416 | channel | Create giveaways |
EVENT_CREATE | 45 | 35184372088832 | channel | Create events |
EVENT_MANAGE | 46 | 70368744177664 | channel | Manage events |
PARTY_CREATE | 47 | 140737488355328 | channel | Create parties |
PARTY_MANAGE | 48 | 281474976710656 | channel | Manage parties |
Adding them up
To ask for View channels (1), Send messages (2) and Read message history (4), send 1 + 2 + 4 = 7. In code, add or | the values.
Values go up to 248, which is below 253, so an ordinary JavaScript number holds them exactly - but JavaScript's | and & operators work on 32 bits and silently cut higher bits off. Use BigInt for bit arithmetic:
Adding and checking permission bits
js
const VIEW_CHANNEL = 1n << 0n
const SEND_MESSAGES = 1n << 1n
const READ_HISTORY = 1n << 2n
const permissions = VIEW_CHANNEL | SEND_MESSAGES | READ_HISTORY // 7n
const has = (held, flag) => (held & flag) === flag
console.log(permissions.toString()) // "7" - what goes in the install linkpython
VIEW_CHANNEL = 1 << 0
SEND_MESSAGES = 1 << 1
READ_HISTORY = 1 << 2
permissions = VIEW_CHANNEL | SEND_MESSAGES | READ_HISTORY # 7
def has(held, flag):
return held & flag == flag
print(str(permissions)) # "7" - what goes in the install linkWho may give what
A person can only give a role, or a bot, permissions they hold themselves; Administrator holds everything. A role can only be managed by someone whose highest role is above it. A bot's managed role is made just below the highest role of the person who added it.