View Source Nostrum.Permission (Nostrum v0.10.0)

Functions that work on permissions.

Some functions return a list of permissions. You can use enumerable functions to work with permissions:

alias Nostrum.Cache.GuildCache
alias Nostrum.Struct.Guild.Member

guild = GuildCache.get!(279093381723062272)
member = Map.get(guild.members, 177888205536886784)
member_perms = Member.guild_permissions(member, guild)

if :administrator in member_perms do
  IO.puts("This user has the administrator permission.")
end

Summary

Types

Represents a single permission as a bitvalue.

Represents a set of permissions as a bitvalue.

t()

Functions

Returns a list of all permissions.

Converts the given bit to a permission.

Same as from_bit/1, but raises ArgumentError in case of failure.

Converts the given bitset to a list of permissions.

Returns true if term is a permission; otherwise returns false.

Converts the given permission to a bit.

Converts the given enumerable of permissions to a bitset.

Types

@type bit() :: non_neg_integer()

Represents a single permission as a bitvalue.

@type bitset() :: non_neg_integer()

Represents a set of permissions as a bitvalue.

@type general_permission() ::
  :create_instant_invite
  | :kick_members
  | :ban_members
  | :administrator
  | :manage_channels
  | :manage_guild
  | :view_audit_log
  | :view_channel
  | :change_nickname
  | :manage_nicknames
  | :manage_roles
  | :manage_webhooks
  | :manage_guild_expressions
  | :view_guild_insights
  | :use_application_commands
  | :moderate_members
  | :create_guild_expressions
  | :send_polls
@type text_permission() ::
  :add_reactions
  | :send_messages
  | :send_tts_messages
  | :manage_messages
  | :embed_links
  | :attach_files
  | :read_message_history
  | :mention_everyone
  | :use_external_emojis
  | :create_public_threads
  | :create_private_threads
  | :send_messages_in_threads
  | :manage_threads
  | :use_external_stickers
@type voice_permission() ::
  :connect
  | :speak
  | :mute_members
  | :deafen_members
  | :move_members
  | :use_vad
  | :priority_speaker
  | :stream
  | :request_to_speak
  | :manage_events
  | :use_embedded_activities

Functions

@spec all() :: [t()]

Returns a list of all permissions.

@spec from_bit(bit()) :: {:ok, t()} | :error

Converts the given bit to a permission.

This function returns :error if bit does not map to a permission.

Examples

iex> Nostrum.Permission.from_bit(0x04000000)
{:ok, :change_nickname}

iex> Nostrum.Permission.from_bit(0)
:error
@spec from_bit!(bit()) :: t()

Same as from_bit/1, but raises ArgumentError in case of failure.

Examples

iex> Nostrum.Permission.from_bit!(0x04000000)
:change_nickname

iex> Nostrum.Permission.from_bit!(0)
** (ArgumentError) expected a valid bit, got: `0`
@spec from_bitset(bitset()) :: [t()]

Converts the given bitset to a list of permissions.

If invalid bits are given they will be omitted from the results.

Examples

iex> Nostrum.Permission.from_bitset(0x08000002)
[:manage_nicknames, :kick_members]

iex> Nostrum.Permission.from_bitset(0x4000000000000)
[]
Link to this macro

is_permission(term)

View Source (macro)

Returns true if term is a permission; otherwise returns false.

Examples

iex> Nostrum.Permission.is_permission(:administrator)
true

iex> Nostrum.Permission.is_permission(:not_a_permission)
false
@spec to_bit(t()) :: bit()

Converts the given permission to a bit.

Examples

iex> Nostrum.Permission.to_bit(:administrator)
8
@spec to_bitset(Enum.t()) :: bitset()

Converts the given enumerable of permissions to a bitset.

Examples

iex> Nostrum.Permission.to_bitset([:administrator, :create_instant_invite])
9