Struct serenity::model::user::User

source ·
#[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
Non-exhaustive structs could have additional fields added in future. Therefore, non-exhaustive structs cannot be constructed in external crates using the traditional 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

§banner: Option<ImageHash>

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

§premium_type: PremiumType

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.

Discord docs.

Implementations§

source§

impl User

source

pub fn avatar_url(&self) -> Option<String>

Available on crate feature model only.

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.

source

pub fn banner_url(&self) -> Option<String>

Available on crate feature model only.

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.

source

pub async fn create_dm_channel( &self, cache_http: impl CacheHttp ) -> Result<PrivateChannel>

Available on crate feature model only.

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.

source

pub fn created_at(&self) -> Timestamp

Available on crate feature model only.

Retrieves the time that this user was created at.

source

pub fn default_avatar_url(&self) -> String

Available on crate feature model only.

Returns the formatted URL to the user’s default avatar URL.

This will produce a PNG URL.

source

pub async fn direct_message( &self, cache_http: impl CacheHttp, builder: CreateMessage ) -> Result<Message>

Available on crate feature model only.

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.

source

pub async fn dm( &self, cache_http: impl CacheHttp, builder: CreateMessage ) -> Result<Message>

Available on crate feature model only.

This is an alias of Self::direct_message.

source

pub fn face(&self) -> String

Available on crate feature model only.

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.

source

pub fn static_face(&self) -> String

Available on crate feature model only.

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.

source

pub async fn has_role( &self, cache_http: impl CacheHttp, guild_id: impl Into<GuildId>, role: impl Into<RoleId> ) -> Result<bool>

Available on crate feature model only.

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.

source

pub async fn refresh(&mut self, cache_http: impl CacheHttp) -> Result<()>

Available on crate feature model only.

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.

source

pub fn static_avatar_url(&self) -> Option<String>

Available on crate feature model only.

Returns a static formatted URL of the user’s icon, if one exists.

This will always produce a WEBP image URL.

source

pub fn tag(&self) -> String

Available on crate feature model only.

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;
        }
    }
}
source

pub async fn nick_in( &self, cache_http: impl CacheHttp, guild_id: impl Into<GuildId> ) -> Option<String>

Available on crate feature model only.

Returns the user’s nickname in the given guild_id.

If none is used, it returns None.

source

pub fn await_reply( &self, shard_messenger: impl AsRef<ShardMessenger> ) -> MessageCollector

Available on crate features model and collector only.

Returns a builder which can be awaited to obtain a message or stream of messages sent by this user.

source

pub fn await_replies( &self, shard_messenger: impl AsRef<ShardMessenger> ) -> MessageCollector

Available on crate features model and collector only.
source

pub fn await_reaction( &self, shard_messenger: impl AsRef<ShardMessenger> ) -> ReactionCollector

Available on crate features model and collector only.

Returns a builder which can be awaited to obtain a reaction or stream of reactions sent by this user.

source

pub fn await_reactions( &self, shard_messenger: impl AsRef<ShardMessenger> ) -> ReactionCollector

Available on crate features model and collector only.

Trait Implementations§

source§

impl ArgumentConvert for User

Available on crate features client and utils only.

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):

  1. Lookup by ID.
  2. Lookup by mention.
  3. Lookup by name#discrim.
  4. Lookup by name
§

type Err = UserParseError

The associated error which can be returned from parsing.
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,

Parses a string s as a command parameter of this type.
source§

impl Clone for User

source§

fn clone(&self) -> User

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for User

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl Default for User

source§

fn default() -> User

Returns the “default value” for a type. Read more
source§

impl<'de> Deserialize<'de> for User

source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
source§

impl Display for User

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats a string which will mention the user.

source§

impl<'a> From<&'a User> for UserId

source§

fn from(user: &User) -> UserId

Gets the Id of a User.

source§

impl From<CurrentUser> for User

source§

fn from(user: CurrentUser) -> Self

Converts to this type from the input type.
source§

impl From<User> for CreateEmbedAuthor

Available on crate features builder and model only.
source§

fn from(user: User) -> Self

Converts to this type from the input type.
source§

impl From<User> for UserId

source§

fn from(user: User) -> UserId

Gets the Id of a User.

source§

impl Hash for User

source§

fn hash<H: Hasher>(&self, hasher: &mut H)

Feeds this value into the given Hasher. Read more
1.3.0 · source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
source§

impl Mentionable for User

source§

fn mention(&self) -> Mention

Creates a Mention that will be able to notify or create a link to the item. Read more
source§

impl PartialEq for User

source§

fn eq(&self, other: &Self) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl Serialize for User

source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
source§

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> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> CloneDebuggableStorage for T

source§

impl<T> CloneableStorage for T
where T: Any + Send + Sync + Clone,

source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T> Instrument for T

source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> Same for T

§

type Output = T

Should always be Self
source§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T> ToString for T
where T: Display + ?Sized,

source§

default fn to_string(&self) -> String

Converts the given value to a String. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

source§

fn vzip(self) -> V

source§

impl<T> WithSubscriber for T

source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
source§

impl<T> DebuggableStorage for T
where T: Any + Send + Sync + Debug,

source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,