crux_structs v0.2.3 Crux.Structs.Role View Source

Represents a Discord Role Object.

Link to this section Summary

Types

All available types that can be resolved into a role id.

All available types that can be resolved into a role position.

t()

Functions

Creates a t:Crux.Structs.Role.t/0 struct from raw data.

Resolves a t:position_resolvable/0 into a role position.

Converts a t:Crux.Structs.Role.t/0 into its discord mention format.

Link to this section Types

Link to this type

id_resolvable()

View Source (since 0.2.1)

Specs

id_resolvable() ::
  Crux.Structs.Role.t() | Crux.Structs.Snowflake.t() | String.t() | nil

All available types that can be resolved into a role id.

Link to this type

position_resolvable()

View Source (since 0.2.1)

Specs

position_resolvable() ::
  Crux.Structs.Role.t()
  | %{role: id_resolvable(), position: integer()}
  | {id_resolvable(), integer()}
  | %{id: id_resolvable(), position: integer()}

All available types that can be resolved into a role position.

Specs

t() :: %Crux.Structs.Role{
  color: integer(),
  guild_id: Crux.Structs.Snowflake.t(),
  hoist: boolean(),
  id: Crux.Structs.Snowflake.t(),
  managed: boolean(),
  mentionable: boolean(),
  name: String.t(),
  permissions: Crux.Structs.Permissions.raw(),
  position: integer()
}

Link to this section Functions

Link to this function

create(data)

View Source (since 0.1.0)

Specs

create(data :: map()) :: t()

Creates a t:Crux.Structs.Role.t/0 struct from raw data.

Automatically invoked by Crux.Structs.create/2.

Link to this function

resolve_position(resolvable)

View Source (since 0.2.1)

Specs

resolve_position(position_resolvable()) ::
  %{id: Crux.Structs.Snowflake.t(), position: integer()} | nil

Resolves a t:position_resolvable/0 into a role position.

Examples

  iex> {%Crux.Structs.Role{id: 373405430589816834}, 5}
  ...> |> Crux.Structs.Role.resolve_position()
  %{id: 373405430589816834, position: 5}

  iex> %Crux.Structs.Role{id: 373405430589816834, position: 5}
  ...> |> Crux.Structs.Role.resolve_position()
  %{id: 373405430589816834, position: 5}

  iex> %{id: 373405430589816834, position: 5}
  ...> |> Crux.Structs.Role.resolve_position()
  %{id: 373405430589816834, position: 5}

  iex> %{role: %Crux.Structs.Role{id: 373405430589816834}, position: 5}
  ...> |> Crux.Structs.Role.resolve_position()
  %{id: 373405430589816834, position: 5}

  iex> {373405430589816834, 5}
  ...> |> Crux.Structs.Role.resolve_position()
  %{id: 373405430589816834, position: 5}

  iex> {nil, 5}
  ...> |> Crux.Structs.Role.resolve_position()
  nil
Link to this function

to_mention(role)

View Source (since 0.1.1)

Specs

to_mention(user :: Crux.Structs.Role.t()) :: String.t()

Converts a t:Crux.Structs.Role.t/0 into its discord mention format.

Example

iex> %Crux.Structs.Role{id: 376146940762783746}
...> |> Crux.Structs.Role.to_mention()
"<@&376146940762783746>"