EDA.User (EDA v0.5.0-beta.2)

Copy Markdown View Source

Represents a Discord user.

Summary

Types

A Nitro tier name.

t()

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.

Returns true if the user is known to have some form of Nitro.

Names the user's Nitro tier.

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

Types

premium_type()

@type premium_type() ::
  :none | :nitro_classic | :nitro | :nitro_basic | :unknown | nil

A Nitro tier name.

t()

@type t() :: %EDA.User{
  accent_color: integer() | nil,
  avatar: String.t() | nil,
  avatar_decoration_data: map() | nil,
  banner: String.t() | nil,
  bot: boolean() | nil,
  collectibles: map() | nil,
  discriminator: String.t() | nil,
  email: String.t() | nil,
  flags: integer() | nil,
  global_name: String.t() | nil,
  id: String.t() | nil,
  locale: String.t() | nil,
  mfa_enabled: boolean() | nil,
  premium_type: integer() | nil,
  primary_guild: EDA.User.PrimaryGuild.t() | nil,
  public_flags: integer() | nil,
  system: boolean() | nil,
  username: String.t() | nil,
  verified: boolean() | 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).

Not the raw display_name field

Discord also sends an undocumented display_name on the user object, and it is not the same answer: it is null whenever the user has no global name. Measured on a real guild on 2026-09-19, 46 of 573 cached users had display_name: null — every bot among them. This function falls back to the username instead, so it always names somebody. Do not "fix" it by reading the raw field.

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.

nitro?(user)

@spec nitro?(t() | map() | integer() | nil) :: boolean()

Returns true if the user is known to have some form of Nitro.

false covers both "no Nitro" and "not told", since neither entitles the user to anything — see premium_type/1 if you need to tell those apart.

Examples

iex> EDA.User.nitro?(%EDA.User{premium_type: 3})
true

iex> EDA.User.nitro?(%EDA.User{premium_type: 0})
false

iex> EDA.User.nitro?(%EDA.User{})
false

premium_type(value)

@spec premium_type(t() | map() | integer() | nil) :: premium_type()

Names the user's Nitro tier.

Returns nil when Discord did not send the field, which is the usual case: premium_type needs the identify.premium OAuth2 scope and never appears on a user seen through the gateway or the REST API. nil therefore means not known.

:none is only meaningful for an app approved for identify.premium, a scope Discord grants to partners only. For every other app Discord answers 0 whatever the user's subscription, so :none there says nothing about their Nitro either.

Examples

iex> EDA.User.premium_type(%EDA.User{premium_type: 2})
:nitro

iex> EDA.User.premium_type(%EDA.User{premium_type: 0})
:none

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

iex> EDA.User.premium_type(%EDA.User{premium_type: 99})
:unknown

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