glyde/permissions

Permission bitfields, which Discord sends as a decimal string holding 64 bits.

Types

Why a string is not a permission field. Each carries the text it refused, so a caller logging one does not have to hold on to the input.

pub type ParseError {
  NotDecimal(decimal: String)
  TooWide(decimal: String)
}

Constructors

  • NotDecimal(decimal: String)

    Not one or more decimal digits.

  • TooWide(decimal: String)

    Wider than the 64 bits Discord specifies. Keeping the bottom 64 would grant a set nobody wrote.

One permission, named after Discord’s constant for it.

pub type Permission {
  CreateInstantInvite
  KickMembers
  BanMembers
  Administrator
  ManageChannels
  ManageGuild
  AddReactions
  ViewAuditLog
  PrioritySpeaker
  Stream
  ViewChannel
  SendMessages
  SendTtsMessages
  ManageMessages
  EmbedLinks
  AttachFiles
  ReadMessageHistory
  MentionEveryone
  UseExternalEmojis
  ViewGuildInsights
  Connect
  Speak
  MuteMembers
  DeafenMembers
  MoveMembers
  UseVad
  ChangeNickname
  ManageNicknames
  ManageRoles
  ManageWebhooks
  ManageGuildExpressions
  UseApplicationCommands
  RequestToSpeak
  ManageEvents
  ManageThreads
  CreatePublicThreads
  CreatePrivateThreads
  UseExternalStickers
  SendMessagesInThreads
  UseEmbeddedActivities
  ModerateMembers
  ViewCreatorMonetizationAnalytics
  UseSoundboard
  CreateGuildExpressions
  CreateEvents
  UseExternalSounds
  SendVoiceMessages
  SetVoiceChannelStatus
  SendPolls
  UseExternalApps
  PinMessages
  BypassSlowmode
}

Constructors

  • CreateInstantInvite
  • KickMembers
  • BanMembers
  • Administrator
  • ManageChannels
  • ManageGuild
  • AddReactions
  • ViewAuditLog
  • PrioritySpeaker
  • Stream

    Called Video in the Discord client.

  • ViewChannel
  • SendMessages
  • SendTtsMessages
  • ManageMessages
  • EmbedLinks
  • AttachFiles
  • ReadMessageHistory
  • MentionEveryone
  • UseExternalEmojis
  • ViewGuildInsights
  • Connect
  • Speak
  • MuteMembers
  • DeafenMembers
  • MoveMembers
  • UseVad

    Speak by voice activity rather than push to talk.

  • ChangeNickname
  • ManageNicknames
  • ManageRoles
  • ManageWebhooks
  • ManageGuildExpressions
  • UseApplicationCommands
  • RequestToSpeak
  • ManageEvents
  • ManageThreads
  • CreatePublicThreads
  • CreatePrivateThreads
  • UseExternalStickers
  • SendMessagesInThreads
  • UseEmbeddedActivities
  • ModerateMembers

    Time a member out.

  • ViewCreatorMonetizationAnalytics
  • UseSoundboard
  • CreateGuildExpressions
  • CreateEvents
  • UseExternalSounds
  • SendVoiceMessages
  • SetVoiceChannelStatus
  • SendPolls
  • UseExternalApps
  • PinMessages
  • BypassSlowmode

A set of permissions. Bits Discord has not named yet ride along, so a value read off the wire and written back is what arrived.

pub opaque type Permissions

Values

pub fn add(
  permissions: Permissions,
  permission: Permission,
) -> Permissions
pub fn all() -> Permissions

Every permission Discord documents. Discord itself never sends this: a role that can do everything carries Administrator instead.

pub fn all_permissions() -> List(Permission)

Every permission Discord currently documents, in bit order.

pub fn allows(
  permissions: Permissions,
  permission: Permission,
) -> Bool

Whether an effective permission set permits this. Administrator grants everything, which is Discord’s rule and not a property of the bitfield, so only ask this of a set you have already resolved. On a role’s bits or on an overwrite’s allow or deny it reads a plain Administrator bit as everything, which no side of an overwrite means.

pub fn bit_index(permission: Permission) -> Int

The bit number, not its value, from Discord’s permissions table. Bit 47 is missing, retired by Discord.

pub fn contains(
  permissions: Permissions,
  permission: Permission,
) -> Bool

Whether the bit is set, and nothing else. This is the honest question for a role’s own bits and for either side of a channel overwrite.

pub fn decoder() -> decode.Decoder(Permissions)

Strings only, like an id: Discord always sends a bitfield as a string, so a number in that slot is a malformed payload.

pub fn difference(a: Permissions, b: Permissions) -> Permissions

Everything in a that is not in b, which is what a channel overwrite’s deny list does.

pub fn new(granted: List(Permission)) -> Permissions
pub fn none() -> Permissions
pub fn parse(decimal: String) -> Result(Permissions, ParseError)

Rejects anything that is not decimal digits, and anything wider than the 64 bits Discord specifies rather than keeping the bottom of it.

pub fn remove(
  permissions: Permissions,
  permission: Permission,
) -> Permissions
pub fn to_json(permissions: Permissions) -> json.Json
pub fn to_list(permissions: Permissions) -> List(Permission)

In bit order, and only the ones this build names. A bit assigned since is still carried through to_string untouched.

pub fn to_string(permissions: Permissions) -> String

The bitfield to send, as the decimal string Discord expects.

Search Document