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.
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
@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
Returns the CDN URL for the user's avatar, or nil if none set.
Accepts both %EDA.User{} structs and raw maps (from cache).
Returns true if the user is a bot. Accepts structs and raw maps.
@spec change(EDA.Entity.Changeset.t(), atom(), term()) :: EDA.Entity.Changeset.t()
Adds a change to an existing changeset for this entity.
@spec changeset(t()) :: EDA.Entity.Changeset.t()
Creates a changeset for batching mutations to this entity.
@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.
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.
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.
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
Returns a mention string like <@id>. Accepts structs and raw maps.
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
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