Alchemy.Permissions (alchemy v0.7.0)

This module contains useful functions for working for the permission bitsets discord provides.

To combine the permissions of an overwrite with the permissions of a role, the bitwise ||| can be used.

Example Usage

Cogs.def perms(role_name) do
  {:ok, guild} = Cogs.guild()
  role = hd Enum.filter(guild.roles, & &1.name == role_name)
  Cogs.say(inspect Permissions.to_list(role.permission))
end

This simple command prints out the list of permissions a role has avaiable.

Permission List

  • :create_instant_invite Allows the creation of instant invites.
  • :kick_members Allows the kicking of members.
  • :ban_members Allows the banning of members.
  • :administrator Allows all permissions, and bypasses channel overwrites.
  • :manage_channels Allows management and editing of channels.
  • :manage_guild Allows management and editing of the guild.
  • :add_reactions Allows adding reactions to message.
  • :view_audit_log Allows for viewing of audit logs.
  • :read_messages Allows reading messages in a channel. Without this, the user won't even see the channel.
  • :send_messages Allows sending messages in a channel.
  • :send_tts_messages Allows sending text to speech messages.
  • :manage_messages Allows for deletion of other user messages.
  • :embed_links Links sent with this permission will be embedded automatically
  • :attach_files Allows the user to send files, and images
  • :read_message_history Allows the user to read the message history of a channel
  • :mention_everyone Allows the user to mention the special @everyone and @here tags
  • :use_external_emojis Allows the user to use emojis from other servers.
  • :connect Allows the user to connect to a voice channel.
  • :speak Allows the user to speak in a voice channel.
  • :mute_members Allows the user to mute members in a voice channel.
  • :deafen_members Allows the user to deafen members in a voice channel.
  • :move_members Allows the user to move members between voice channels.
  • :use_vad Allows the user to use voice activity detection in a voice channel
  • :change_nickname Allows the user to change his own nickname.
  • :manage_nicknames Allows for modification of other user nicknames.
  • :manage_roles Allows for management and editing of roles.
  • :manage_webhooks Allows for management and editing of webhooks.
  • :manage_emojis Allows for management and editing of emojis.

Link to this section Summary

Functions

Gets the actual permissions of a member in a guild channel.

Checks for the presence of a permission in a permission bitset.

Converts a list of permission atoms into a bitset. This is the reverse operation of to_list/1.

Converts a permission bitset into a legible list of atoms. This is the reverse operation of to_bitset/1.

Link to this section Types

Link to this type

permission()

Specs

permission() :: atom()

Link to this section Functions

Link to this function

channel_permissions(member, guild, channel_id)

Gets the actual permissions of a member in a guild channel.

This will error if the channel_id passed isn't in the guild. This will mismatch if the wrong structs are passed, or if the guild doesn't have a channel field.

Link to this function

channel_permissions!(member, guild, channel_id)

Banged version of channel_permissions/3

Link to this function

contains?(bitset, permission)

Specs

contains?(Integer, permission()) :: Boolean

Checks for the presence of a permission in a permission bitset.

This should be preferred over using :perm in Permissions.to_list(x) because this works directly using bitwise operations, and is much more efficient then going through the permissions.

Examples

Permissions.contains?(role.permissions, :manage_roles)
Link to this function

to_bitset(list)

Specs

to_bitset([permission()]) :: Integer

Converts a list of permission atoms into a bitset. This is the reverse operation of to_list/1.

Examples

bitset = Permissions.to_bitset([:send_messages, :speak])
Link to this function

to_list(bitset)

Specs

to_list(Integer) :: [permission()]

Converts a permission bitset into a legible list of atoms. This is the reverse operation of to_bitset/1.

For checking if a specific permission is in that list, use contains?/2 instead.

Examples

permissions = Permissions.to_list(role.permissions)