View Source Nostrum.Struct.User (Nostrum v0.9.0-rc1)
Struct representing a Discord user.
Mentioning Users in Messages
A Nostrum.Struct.User
can be mentioned in message content using the String.Chars
protocol or mention/1
.
user = %Nostrum.Struct.User{id: 120571255635181568}
Nostrum.Api.create_message!(184046599834435585, "#{user}")
%Nostrum.Struct.Message{content: "<@120571255635181568>"}
user = %Nostrum.Struct.User{id: 89918932789497856}
Nostrum.Api.create_message!(280085880452939778, "#{Nostrum.Struct.User.mention(user)}")
%Nostrum.Struct.Message{content: "<@89918932789497856>"}
User vs. Member
A user
contains only general information about that user such as a username
and an avatar
.
A member
has everything that a user
has, but also additional information on a per guild basis. This includes things like a nickname
and a list of roles
.
Summary
Types
User's avatar hash
Whether the user is a bot
The user's 4--digit discord-tag
The user's email
The user's display name, if it is set
The user's id
Whether the user has two factor enabled
The user's public flags
The user's username
Whether the email on the account has been verified
Functions
Returns the URL of a user's display avatar.
Returns a user's :global_name
if present, otherwise returns their
:username
and :discriminator
separated by a hashtag.
Formats an Nostrum.Struct.User
into a mention.
Types
@type avatar() :: String.t() | nil
User's avatar hash
@type bot() :: boolean() | nil
Whether the user is a bot
@type discriminator() :: String.t()
The user's 4--digit discord-tag
@type email() :: String.t() | nil
The user's email
@type global_name() :: String.t() | nil
The user's display name, if it is set
@type id() :: Nostrum.Snowflake.t()
The user's id
@type mfa_enabled() :: boolean() | nil
Whether the user has two factor enabled
@type public_flags() :: Nostrum.Struct.User.Flags.t()
The user's public flags
@type t() :: %Nostrum.Struct.User{ avatar: avatar(), bot: bot(), discriminator: discriminator(), email: email(), global_name: global_name(), id: id(), mfa_enabled: mfa_enabled(), public_flags: public_flags(), username: username(), verified: verified() }
@type username() :: String.t()
The user's username
@type verified() :: boolean() | nil
Whether the email on the account has been verified
Functions
Returns the URL of a user's display avatar.
If :avatar
is nil
, the default avatar url is returned.
Supported image formats are PNG, JPEG, WebP, and GIF.
Examples
iex> user = %Nostrum.Struct.User{avatar: "8342729096ea3675442027381ff50dfe",
...> id: 80351110224678912}
iex> Nostrum.Struct.User.avatar_url(user)
"https://cdn.discordapp.com/avatars/80351110224678912/8342729096ea3675442027381ff50dfe.webp"
iex> Nostrum.Struct.User.avatar_url(user, "png")
"https://cdn.discordapp.com/avatars/80351110224678912/8342729096ea3675442027381ff50dfe.png"
iex> user = %Nostrum.Struct.User{avatar: nil,
...> id: 80351110224678912,
...> discriminator: "0"}
iex> Nostrum.Struct.User.avatar_url(user)
"https://cdn.discordapp.com/embed/avatars/5.png"
iex> user = %Nostrum.Struct.User{avatar: nil,
...> discriminator: "1337"}
iex> Nostrum.Struct.User.avatar_url(user)
"https://cdn.discordapp.com/embed/avatars/2.png"
Returns a user's :global_name
if present, otherwise returns their
:username
and :discriminator
separated by a hashtag.
Examples
iex> user = %Nostrum.Struct.User{global_name: "TheRealJason",
...> username: "therealjason",
...> discriminator: "0"}
iex> Nostrum.Struct.User.full_name(user)
"TheRealJason"
iex> user = %Nostrum.Struct.User{username: "b1nzy",
...> discriminator: "0852"}
iex> Nostrum.Struct.User.full_name(user)
"b1nzy#0852"
Formats an Nostrum.Struct.User
into a mention.
Examples
iex> user = %Nostrum.Struct.User{id: 177888205536886784}
...> Nostrum.Struct.User.mention(user)
"<@177888205536886784>"