#[non_exhaustive]pub struct User {Show 17 fields
pub id: UserId,
pub name: String,
pub discriminator: Option<NonZeroU16>,
pub global_name: Option<String>,
pub avatar: Option<ImageHash>,
pub bot: bool,
pub system: bool,
pub mfa_enabled: bool,
pub banner: Option<ImageHash>,
pub accent_colour: Option<Colour>,
pub locale: Option<String>,
pub verified: Option<bool>,
pub email: Option<String>,
pub flags: UserPublicFlags,
pub premium_type: PremiumType,
pub public_flags: Option<UserPublicFlags>,
pub member: Option<Box<PartialMember>>,
}
Expand description
Information about a user.
Discord docs, existence of additional partial member field documented here.
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: UserId
The unique Id of the user. Can be used to calculate the account’s creation date.
name: String
The account’s username. Changing username will trigger a discriminator change if the username+discriminator pair becomes non-unique. Unless the account has migrated to a next generation username, which does not have a discriminant.
discriminator: Option<NonZeroU16>
The account’s discriminator to differentiate the user from others with
the same Self::name
. The name+discriminator pair is always unique.
If the discriminator is not present, then this is a next generation username
which is implicitly unique.
global_name: Option<String>
The account’s display name, if it is set. For bots this is the application name.
avatar: Option<ImageHash>
Optional avatar hash.
bot: bool
Indicator of whether the user is a bot.
system: bool
Whether the user is an Official Discord System user (part of the urgent message system).
mfa_enabled: bool
Whether the user has two factor enabled on their account
Optional banner hash.
Note: This will only be present if the user is fetched via Rest API, e.g. with
crate::http::Http::get_user
.
accent_colour: Option<Colour>
The user’s banner colour encoded as an integer representation of hexadecimal colour code
Note: This will only be present if the user is fetched via Rest API, e.g. with
crate::http::Http::get_user
.
locale: Option<String>
The user’s chosen language option
verified: Option<bool>
Whether the email on this account has been verified
Requires Scope::Email
email: Option<String>
The user’s email
Requires Scope::Email
flags: UserPublicFlags
The flags on a user’s account
The type of Nitro subscription on a user’s account
public_flags: Option<UserPublicFlags>
The public flags on a user’s account
member: Option<Box<PartialMember>>
Only included in Message::mentions
for messages from the gateway.
Implementations§
Source§impl User
impl User
Sourcepub fn avatar_url(&self) -> Option<String>
pub fn avatar_url(&self) -> Option<String>
Returns the formatted URL of the user’s icon, if one exists.
This will produce a WEBP image URL, or GIF if the user has a GIF avatar.
Returns the formatted URL of the user’s banner, if one exists.
This will produce a WEBP image URL, or GIF if the user has a GIF banner.
Note: This will only be present if the user is fetched via Rest API, e.g. with
crate::http::Http::get_user
.
Sourcepub async fn create_dm_channel(
&self,
cache_http: impl CacheHttp,
) -> Result<PrivateChannel>
pub async fn create_dm_channel( &self, cache_http: impl CacheHttp, ) -> Result<PrivateChannel>
Creates a direct message channel between the current user and the user. This can also retrieve the channel if one already exists.
§Errors
See UserId::create_dm_channel
for what errors may be returned.
Sourcepub fn created_at(&self) -> Timestamp
pub fn created_at(&self) -> Timestamp
Retrieves the time that this user was created at.
Sourcepub fn default_avatar_url(&self) -> String
pub fn default_avatar_url(&self) -> String
Returns the formatted URL to the user’s default avatar URL.
This will produce a PNG URL.
Sourcepub async fn direct_message(
&self,
cache_http: impl CacheHttp,
builder: CreateMessage,
) -> Result<Message>
pub async fn direct_message( &self, cache_http: impl CacheHttp, builder: CreateMessage, ) -> Result<Message>
Sends a message to a user through a direct message channel. This is a channel that can only be accessed by you and the recipient.
§Examples
See UserId::direct_message
for examples.
§Errors
See UserId::direct_message
for errors.
Sourcepub fn display_name(&self) -> &str
pub fn display_name(&self) -> &str
Calculates the user’s display name.
The global name takes priority over the user’s username if it exists.
Note: Guild specific information is not included as this is only available on the Member.
Sourcepub async fn dm(
&self,
cache_http: impl CacheHttp,
builder: CreateMessage,
) -> Result<Message>
pub async fn dm( &self, cache_http: impl CacheHttp, builder: CreateMessage, ) -> Result<Message>
This is an alias of Self::direct_message
.
Sourcepub fn face(&self) -> String
pub fn face(&self) -> String
Retrieves the URL to the user’s avatar, falling back to the default avatar if needed.
This will call Self::avatar_url
first, and if that returns None
, it then falls back
to Self::default_avatar_url
.
Sourcepub fn static_face(&self) -> String
pub fn static_face(&self) -> String
Retrieves the URL to the static version of the user’s avatar, falling back to the default avatar if needed.
This will call Self::static_avatar_url
first, and if that returns None
, it then
falls back to Self::default_avatar_url
.
Sourcepub async fn has_role(
&self,
cache_http: impl CacheHttp,
guild_id: impl Into<GuildId>,
role: impl Into<RoleId>,
) -> Result<bool>
pub async fn has_role( &self, cache_http: impl CacheHttp, guild_id: impl Into<GuildId>, role: impl Into<RoleId>, ) -> Result<bool>
Check if a user has a Role
. This will retrieve the Guild
from the Cache
if it
is available, and then check if that guild has the given Role
.
§Examples
Check if a guild has a Role
by Id:
// Assumes a 'guild_id' and `role_id` have already been bound
let _ = message.author.has_role(guild_id, role_id);
§Errors
Returns an Error::Http
if the given Guild
is unavailable, if that Role
does not
exist in the given Guild
, or if the given User
is not in that Guild
.
May also return an Error::Json
if there is an error in deserializing the API response.
Sourcepub async fn refresh(&mut self, cache_http: impl CacheHttp) -> Result<()>
pub async fn refresh(&mut self, cache_http: impl CacheHttp) -> Result<()>
Refreshes the information about the user.
Replaces the instance with the data retrieved over the REST API.
§Errors
See UserId::to_user
for what errors may be returned.
Sourcepub fn static_avatar_url(&self) -> Option<String>
pub fn static_avatar_url(&self) -> Option<String>
Returns a static formatted URL of the user’s icon, if one exists.
This will always produce a WEBP image URL.
Sourcepub fn tag(&self) -> String
pub fn tag(&self) -> String
Returns the “tag” for the user.
The “tag” is defined as “username#discriminator”, such as “zeyla#5479”.
§Examples
Make a command to tell the user what their tag is:
#[serenity::async_trait]
impl EventHandler for Handler {
async fn message(&self, context: Context, msg: Message) {
if msg.content == "!mytag" {
let content = format!("Your tag is: {}", msg.author.tag());
let _ = msg.channel_id.say(&context.http, &content).await;
}
}
}
Sourcepub async fn nick_in(
&self,
cache_http: impl CacheHttp,
guild_id: impl Into<GuildId>,
) -> Option<String>
pub async fn nick_in( &self, cache_http: impl CacheHttp, guild_id: impl Into<GuildId>, ) -> Option<String>
Returns the user’s nickname in the given guild_id
.
If none is used, it returns None
.
Sourcepub fn await_reply(
&self,
shard_messenger: impl AsRef<ShardMessenger>,
) -> MessageCollector
pub fn await_reply( &self, shard_messenger: impl AsRef<ShardMessenger>, ) -> MessageCollector
Returns a builder which can be awaited to obtain a message or stream of messages sent by this user.
Sourcepub fn await_replies(
&self,
shard_messenger: impl AsRef<ShardMessenger>,
) -> MessageCollector
pub fn await_replies( &self, shard_messenger: impl AsRef<ShardMessenger>, ) -> MessageCollector
Same as Self::await_reply
.
Sourcepub fn await_reaction(
&self,
shard_messenger: impl AsRef<ShardMessenger>,
) -> ReactionCollector
pub fn await_reaction( &self, shard_messenger: impl AsRef<ShardMessenger>, ) -> ReactionCollector
Returns a builder which can be awaited to obtain a reaction or stream of reactions sent by this user.
Sourcepub fn await_reactions(
&self,
shard_messenger: impl AsRef<ShardMessenger>,
) -> ReactionCollector
pub fn await_reactions( &self, shard_messenger: impl AsRef<ShardMessenger>, ) -> ReactionCollector
Same as Self::await_reaction
.
Trait Implementations§
Source§impl ArgumentConvert for User
Look up a user by a string case-insensitively.
impl ArgumentConvert for User
Look up a user by a string case-insensitively.
Requires the cache feature to be enabled. If a user is not in cache, they will not be found!
The lookup strategy is as follows (in order):
- Lookup by ID.
- Lookup by mention.
- Lookup by name#discrim.
- Lookup by name
Source§type Err = UserParseError
type Err = UserParseError
Source§fn convert<'life0, 'async_trait>(
ctx: impl 'async_trait + CacheHttp,
guild_id: Option<GuildId>,
channel_id: Option<ChannelId>,
s: &'life0 str,
) -> Pin<Box<dyn Future<Output = Result<Self, Self::Err>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn convert<'life0, 'async_trait>(
ctx: impl 'async_trait + CacheHttp,
guild_id: Option<GuildId>,
channel_id: Option<ChannelId>,
s: &'life0 str,
) -> Pin<Box<dyn Future<Output = Result<Self, Self::Err>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
s
as a command parameter of this type.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>,
Source§impl From<&User> for CreateEmbedAuthor
impl From<&User> for CreateEmbedAuthor
Source§impl From<CurrentUser> for User
impl From<CurrentUser> for User
Source§fn from(user: CurrentUser) -> Self
fn from(user: CurrentUser) -> Self
Source§impl From<User> for CreateEmbedAuthor
impl From<User> for CreateEmbedAuthor
Source§impl Mentionable for User
impl Mentionable for User
impl Eq for User
Auto Trait Implementations§
impl Freeze for User
impl RefUnwindSafe for User
impl Send for User
impl Sync for User
impl Unpin for User
impl UnwindSafe for User
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneDebuggableStorage for Twhere
T: DebuggableStorage + Clone,
impl<T> CloneDebuggableStorage for Twhere
T: DebuggableStorage + Clone,
fn clone_storage(&self) -> Box<dyn CloneDebuggableStorage>
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> CloneableStorage for T
impl<T> CloneableStorage for T
fn clone_storage(&self) -> Box<dyn CloneableStorage>
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key
and return true
if they are equal.