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
@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
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).
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.
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