#[non_exhaustive]pub struct User {Show 13 fields
pub id: UserId,
pub username: CompactString,
pub discriminator: u16,
pub global_name: Option<CompactString>,
pub avatar: Option<ImageHash>,
pub bot: bool,
pub system: bool,
pub banner: Option<ImageHash>,
pub accent_color: Option<u32>,
pub public_flags: Option<UserFlags>,
pub avatar_decoration_data: Option<Box<AvatarDecorationData>>,
pub collectibles: Option<Box<Collectibles>>,
pub primary_guild: Option<Box<PrimaryGuild>>,
}Expand description
A Discord user — a person or a bot account.
Users are global: they are not tied to a guild. Guild-specific data (nickname, roles, …)
lives on guild members. This type holds the fields Discord sends for any
user; the logged-in user’s own account is a CurrentUser (D-052).
Several fields are only present in some payloads: banner and accent_color only when a
user is fetched directly (GET /users/{user.id}), and message authors of webhooks carry
only the basic fields.
See the user object.
discord.js counterpart: User.
§Examples
use djs_model::user::User;
let user: User = serde_json::from_str(
r#"{"id":"80351110224678912","username":"nelly","discriminator":"0",
"global_name":"Nelly","avatar":null,"public_flags":64}"#,
)?;
assert_eq!(user.display_name(), "Nelly");
assert_eq!(user.tag(), "nelly");Fields (Non-exhaustive)§
This struct is marked as non-exhaustive
Struct { .. } syntax; cannot be matched against without a wildcard ..; and struct update syntax will not work.id: UserIdThe user’s ID.
username: CompactStringThe user’s username. Not unique across the platform for bots; unique for migrated users.
discriminator: u16The legacy four-digit Discord tag, or 0 for users migrated to unique usernames.
Discord sends this as a string ("0", "0420"); it is stored as an integer.
global_name: Option<CompactString>The user’s display name, if set. For bots this is the application name.
avatar: Option<ImageHash>The user’s avatar hash.
bot: boolWhether the user belongs to an OAuth2 application (is a bot).
system: boolWhether the user is an official Discord system user (part of the urgent message system).
The user’s banner hash. Only present when the user is fetched directly.
accent_color: Option<u32>The banner color as an RGB integer (0xRRGGBB), used when there is no banner image.
Only present when the user is fetched directly.
public_flags: Option<UserFlags>The user’s public flags (badges).
avatar_decoration_data: Option<Box<AvatarDecorationData>>The user’s avatar decoration.
collectibles: Option<Box<Collectibles>>The user’s collectibles (nameplate, …).
primary_guild: Option<Box<PrimaryGuild>>The guild whose server tag the user displays.
Implementations§
Source§impl User
impl User
Sourcepub fn display_name(&self) -> &str
pub fn display_name(&self) -> &str
Returns the name to display for this user: the global display name if set, otherwise the username.
discord.js counterpart: User#displayName.
Sourcepub fn tag(&self) -> CompactString
pub fn tag(&self) -> CompactString
Returns the user’s tag: username#1234 for legacy users, or just username for users
migrated to unique usernames (discriminator 0).
discord.js counterpart: User#tag.
§Examples
use djs_model::user::User;
let legacy: User = serde_json::from_str(
r#"{"id":"1","username":"nelly","discriminator":"0042","global_name":null,"avatar":null}"#,
)?;
assert_eq!(legacy.tag(), "nelly#0042");Trait Implementations§
Source§impl<'de> Deserialize<'de> for User
impl<'de> Deserialize<'de> for User
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
impl Eq for User
Source§impl From<CurrentUser> for User
impl From<CurrentUser> for User
Source§fn from(user: CurrentUser) -> Self
fn from(user: CurrentUser) -> Self
Keeps the fields every user has and drops the account-only ones.