EDA.Member (EDA v0.4.0)

Copy Markdown View Source

Represents a Discord guild member.

Summary

Functions

Adds a role to a guild member.

Applies a changeset to a member. No-op if the changeset has no changes.

Adds a change to an existing changeset for this entity.

Creates a changeset for batching mutations to this entity.

Fetches a member by guild ID and user ID. Checks cache first, falls back to REST.

Kicks a member from a guild.

Removes a role from a guild member.

When the member's timeout ends, or nil if they have never been timed out.

Returns true while the member is currently timed out.

Types

t()

@type t() :: %EDA.Member{
  avatar: String.t() | nil,
  communication_disabled_until: String.t() | nil,
  deaf: boolean() | nil,
  joined_at: String.t() | nil,
  mute: boolean() | nil,
  nick: String.t() | nil,
  pending: boolean() | nil,
  premium_since: String.t() | nil,
  roles: [String.t()] | nil,
  user: EDA.User.t() | nil
}

Functions

add_role(guild_id, member, role_id, opts \\ [])

@spec add_role(
  String.t() | integer(),
  t() | String.t() | integer(),
  String.t() | integer(),
  keyword()
) :: :ok | {:error, term()}

Adds a role to a guild member.

Options

  • :reason - Audit log reason

apply_changeset(guild_id, changeset, opts \\ [])

@spec apply_changeset(String.t() | integer(), EDA.Entity.Changeset.t(), keyword()) ::
  {:ok, t()} | {:error, term()}

Applies a changeset to a member. No-op if the changeset has no changes.

Requires guild_id since members are guild-scoped.

Options

  • :reason - Audit log reason

change(cs, key, value)

Adds a change to an existing changeset for this entity.

changeset(entity)

@spec changeset(t()) :: EDA.Entity.Changeset.t()

Creates a changeset for batching mutations to this entity.

fetch_member(guild_id, user_id)

@spec fetch_member(String.t() | integer(), String.t() | integer()) ::
  {:ok, t()} | {:error, term()}

Fetches a member by guild ID and user ID. Checks cache first, falls back to REST.

from_raw(raw)

@spec from_raw(map()) :: t()

kick(guild_id, member, opts \\ [])

@spec kick(String.t() | integer(), t() | String.t() | integer(), keyword()) ::
  :ok | {:error, term()}

Kicks a member from a guild.

Options

  • :reason - Audit log reason

modify(guild_id, member, payload, opts \\ [])

@spec modify(String.t() | integer(), t() | String.t() | integer(), map(), keyword()) ::
  {:ok, t()} | {:error, term()}

Modifies a guild member.

Options

  • :reason - Audit log reason

remove_role(guild_id, member, role_id, opts \\ [])

@spec remove_role(
  String.t() | integer(),
  t() | String.t() | integer(),
  String.t() | integer(),
  keyword()
) :: :ok | {:error, term()}

Removes a role from a guild member.

Options

  • :reason - Audit log reason

time_out_end(member)

@spec time_out_end(t() | map()) :: DateTime.t() | nil

When the member's timeout ends, or nil if they have never been timed out.

May return a date in the past, in which case the timeout has expired — Discord leaves the field populated. Use timed_out?/1 to ask whether it is currently active. JDA draws the same distinction with getTimeOutEnd() / isTimedOut().

Accepts a struct or a raw member map.

Examples

iex> EDA.Member.time_out_end(%EDA.Member{communication_disabled_until: "2099-01-01T00:00:00Z"})
~U[2099-01-01 00:00:00Z]

iex> EDA.Member.time_out_end(%EDA.Member{})
nil

timed_out?(member)

@spec timed_out?(t() | map()) :: boolean()

Returns true while the member is currently timed out.

Accepts a struct or a raw member map.

Not reflected in permissions

Discord removes every permission except VIEW_CHANNEL and READ_MESSAGE_HISTORY from a timed-out member, but EDA.Permission.in_channel/3 does not account for it — neither does JDA's hasPermission. Check this yourself before gating an action on a permission.

Examples

iex> EDA.Member.timed_out?(%EDA.Member{communication_disabled_until: "2099-01-01T00:00:00Z"})
true

iex> EDA.Member.timed_out?(%EDA.Member{communication_disabled_until: "2020-01-01T00:00:00Z"})
false

iex> EDA.Member.timed_out?(%EDA.Member{})
false