alchemy v0.1.9 Alchemy.Permissions
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_inviteAllows the creation of instant invites.:kick_membersAllows the kicking of members.:ban_membersAllows the banning of members.:administratorAllows all permissions, and bypasses channel overwrites.:manage_channelsAllows management and editing of channels.:manage_guildAllows management and editing of the guild.:add_reactionsAllows adding reactions to message.:read_messagesAllows reading messages in a channel. Without this, the user won’t even see the channel.:send_messagesAllows sending messages in a channel.:send_tts_messagesAllows sending text to speech messages.:manage_messagesAllows for deletion of other user messages.:embed_linksLinks sent with this permission will be embedded automatically:attach_filesAllows the user to send files, and images:read_message_historyAllows the user to read the message history of a channel:mention_everyoneAllows the user to mention the special@everyoneand@heretags:use_external_emojisAllows the user to use emojis from other servers.:connectAllows the user to connect to a voice channel.:speakAllows the user to speak in a voice channel.:mute_membersAllows the user to mute members in a voice channel.:deafen_membersAllows the user to deafen members in a voice channel.:move_membersAllows the user to move members between voice channels.:use_vadAllows the user to use voice activity detection in a voice channel:change_nicknameAllows the user to change his own nickname.:manage_nicknamesAllows for modification of other user nicknames.:manage_rolesAllows for management and editing of roles.:manage_webhooksAllows for management and editing of webhooks.:manage_emojisAllows for management and editing of emojis.
Summary
Functions
Checks for the presence of a permission in a permission bitset
Converts a permission bitset into a legible list of atoms
Types
permission :: atom
Functions
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)
Specs
to_list(Integer) :: [permission]
Converts a permission bitset into a legible list of atoms.
For checking if a specific permission is in that list, use contains?/2
instead.
Examples
permissions = Permissions.to_list(role.permissions)