EDA.User (EDA v0.4.0)

Copy Markdown View Source

Represents a Discord user.

Summary

Functions

Returns the CDN URL for the user's avatar, or nil if none set.

Returns true if the user is a bot. Accepts structs and raw maps.

Adds a change to an existing changeset for this entity.

Creates a changeset for batching mutations to this entity.

Creates a DM channel with a user. Returns a %EDA.Channel{} struct.

Returns the display name (global_name if set, otherwise username).

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

Fetches a user by ID. Raises on error.

URL of the user's server tag badge, or nil.

Returns a mention string like <@id>. Accepts structs and raw maps.

The server tag the user is currently displaying, or nil.

Types

t()

@type t() :: %EDA.User{
  accent_color: integer() | nil,
  avatar: String.t() | nil,
  banner: String.t() | nil,
  bot: boolean() | nil,
  discriminator: String.t() | nil,
  flags: integer() | nil,
  global_name: String.t() | nil,
  id: String.t() | nil,
  primary_guild: EDA.User.PrimaryGuild.t() | nil,
  public_flags: integer() | nil,
  system: boolean() | nil,
  username: String.t() | nil
}

Functions

avatar_url(arg1)

@spec avatar_url(t() | map()) :: String.t() | nil

Returns the CDN URL for the user's avatar, or nil if none set.

Accepts both %EDA.User{} structs and raw maps (from cache).

bot?(arg1)

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

Returns true if the user is a bot. Accepts structs and raw maps.

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.

create_dm(user_id)

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

Creates a DM channel with a user. Returns a %EDA.Channel{} struct.

display_name(arg1)

@spec display_name(t() | map()) :: String.t() | nil

Returns the display name (global_name if set, otherwise username).

Accepts both %EDA.User{} structs and raw maps (from cache).

fetch(user_id)

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

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

fetch!(user_id)

@spec fetch!(t() | String.t() | integer()) :: t()

Fetches a user by ID. Raises on error.

from_raw(raw)

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

guild_tag_badge_url(user, opts \\ [])

@spec guild_tag_badge_url(
  t() | map(),
  keyword()
) :: String.t() | nil

URL of the user's server tag badge, or nil.

discord.js exposes the same helper on the user (guildTagBadgeURL()) rather than only on the nested object, because that is where callers have it to hand. Accepts a struct or a raw user map, like avatar_url/1.

Options

  • :size — power of two between 16 and 4096

Examples

iex> EDA.User.guild_tag_badge_url(%EDA.User{primary_guild: %EDA.User.PrimaryGuild{identity_guild_id: "1", badge: "abc"}})
"https://cdn.discordapp.com/guild-tag-badges/1/abc.png"

iex> EDA.User.guild_tag_badge_url(%EDA.User{})
nil

mention(arg1)

@spec mention(t() | map()) :: String.t()

Returns a mention string like <@id>. Accepts structs and raw maps.

server_tag(user)

@spec server_tag(t() | map()) :: String.t() | nil

The server tag the user is currently displaying, or nil.

Returns nil when there is no primary guild, or when the tag exists but is not being shown — identity_enabled is tri-state, see EDA.User.PrimaryGuild.

Examples

iex> EDA.User.server_tag(%EDA.User{primary_guild: %EDA.User.PrimaryGuild{identity_enabled: true, tag: "DISC"}})
"DISC"

iex> EDA.User.server_tag(%EDA.User{primary_guild: %EDA.User.PrimaryGuild{identity_enabled: false, tag: "DISC"}})
nil

iex> EDA.User.server_tag(%EDA.User{})
nil