[−][src]Struct serenity::model::user::User
Information about a user.
Fields
id: UserId
The unique Id of the user. Can be used to calculate the account's creation date.
avatar: Option<String>
Optional avatar hash.
bot: bool
Indicator of whether the user is a bot.
discriminator: u16
The account's discriminator to differentiate the user from others with
the same name
. The name+discriminator pair is always unique.
name: String
The account's username. Changing username will trigger a discriminator change if the username+discriminator pair becomes non-unique.
Methods
impl User
[src]
impl User
pub fn avatar_url(&self) -> Option<String>
[src]
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.
pub fn create_dm_channel(&self) -> Result<PrivateChannel>
[src]
pub fn create_dm_channel(&self) -> Result<PrivateChannel>
Creates a direct message channel between the current user and the user. This can also retrieve the channel if one already exists.
pub fn created_at(&self) -> NaiveDateTime
[src]
pub fn created_at(&self) -> NaiveDateTime
Retrieves the time that this user was created at.
pub fn default_avatar_url(&self) -> String
[src]
pub fn default_avatar_url(&self) -> String
Returns the formatted URL to the user's default avatar URL.
This will produce a PNG URL.
pub fn direct_message<F>(&self, f: F) -> Result<Message> where
F: FnOnce(CreateMessage) -> CreateMessage,
[src]
pub fn direct_message<F>(&self, f: F) -> Result<Message> where
F: FnOnce(CreateMessage) -> CreateMessage,
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
When a user sends a message with a content of "~help"
, DM the author a
help message, and then react with '👌'
to verify message sending:
use serenity::model::Permissions; use serenity::CACHE; struct Handler; impl EventHandler for Handler { fn message(&self, _: Context, msg: Message) { if msg.content == "~help" { let cache = CACHE.read(); let url = match cache.user.invite_url(Permissions::empty()) { Ok(v) => v, Err(why) => { println!("Error creating invite url: {:?}", why); return; }, }; let help = format!( "Helpful info here. Invite me with this link: <{}>", url, ); match msg.author.direct_message(|m| m.content(&help)) { Ok(_) => { let _ = msg.react('👌'); }, Err(why) => { println!("Err sending help: {:?}", why); let _ = msg.reply("There was an error DMing you help."); }, }; } } } let mut client = Client::new("token", Handler);
Examples
Returns a ModelError::MessagingBot
if the user being direct messaged
is a bot user.
pub fn dm<F: FnOnce(CreateMessage) -> CreateMessage>(
&self,
f: F
) -> Result<Message>
[src]
pub fn dm<F: FnOnce(CreateMessage) -> CreateMessage>(
&self,
f: F
) -> Result<Message>
This is an alias of direct_message.
Examples
Sending a message:
// assuming you are in a context let _ = message.author.dm("Hello!");
Examples
Returns a ModelError::MessagingBot
if the user being direct messaged
is a bot user.
pub fn face(&self) -> String
[src]
pub fn face(&self) -> String
Retrieves the URL to the user's avatar, falling back to the default avatar if needed.
This will call avatar_url
first, and if that returns None
, it
then falls back to default_avatar_url
.
pub fn has_role<G, R>(&self, guild: G, role: R) -> bool where
G: Into<GuildContainer>,
R: Into<RoleId>,
[src]
pub fn has_role<G, R>(&self, guild: G, role: R) -> bool where
G: Into<GuildContainer>,
R: Into<RoleId>,
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
.
Three forms of data may be passed in to the guild parameter: either a
PartialGuild
, a GuildId
, or a u64
.
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);
pub fn refresh(&mut self) -> Result<()>
[src]
pub fn refresh(&mut self) -> Result<()>
Refreshes the information about the user.
Replaces the instance with the data retrieved over the REST API.
Examples
If maintaining a very long-running bot, you may want to periodically refresh information about certain users if the state becomes out-of-sync:
struct Handler; impl EventHandler for Handler { fn message(&self, _: Context, _: Message) { // normal message handling here } } let mut client = Client::new("token", Handler).unwrap(); use serenity::model::id::UserId; use serenity::CACHE; use std::thread; use std::time::Duration; let special_users = vec![UserId(114941315417899012), UserId(87600987040120832)]; // start a new thread to periodically refresh the special users' data // every 12 hours let handle = thread::spawn(move || { // 12 hours in seconds let duration = Duration::from_secs(43200); loop { thread::sleep(duration); let cache = CACHE.read(); for id in &special_users { if let Some(user) = cache.user(*id) { if let Err(why) = user.write().refresh() { println!("Error refreshing {}: {:?}", id, why); } } } } }); println!("{:?}", client.start());
pub fn static_avatar_url(&self) -> Option<String>
[src]
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.
pub fn tag(&self) -> String
[src]
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:
use serenity::utils::MessageBuilder; use serenity::utils::ContentModifier::Bold; struct Handler; impl EventHandler for Handler { fn message(&self, _: Context, msg: Message) { if msg.content == "!mytag" { let content = MessageBuilder::new() .push("Your tag is ") .push(Bold + msg.author.tag()) .build(); let _ = msg.channel_id.say(&content); } } } let mut client = Client::new("token", Handler).unwrap(); client.start().unwrap();
pub fn nick_in<G>(&self, guild_id: G) -> Option<String> where
G: Into<GuildId>,
[src]
pub fn nick_in<G>(&self, guild_id: G) -> Option<String> where
G: Into<GuildId>,
Returns the user's nickname in the given guild_id
.
If none is used, it returns None
.
Trait Implementations
impl Mentionable for User
[src]
impl Mentionable for User
fn mention(&self) -> String
[src]
fn mention(&self) -> String
Creates a mentionable string, that will be able to notify and/or create a link to the item. Read more
impl PartialEq<User> for User
[src]
impl PartialEq<User> for User
fn eq(&self, other: &Self) -> bool
[src]
fn eq(&self, other: &Self) -> bool
This method tests for self
and other
values to be equal, and is used by ==
. Read more
#[must_use]
fn ne(&self, other: &Rhs) -> bool
1.0.0[src]
#[must_use]
fn ne(&self, other: &Rhs) -> bool
This method tests for !=
.
impl From<CurrentUser> for User
[src]
impl From<CurrentUser> for User
fn from(user: CurrentUser) -> Self
[src]
fn from(user: CurrentUser) -> Self
Performs the conversion.
impl<'a> From<&'a CurrentUser> for User
[src]
impl<'a> From<&'a CurrentUser> for User
fn from(user: &'a CurrentUser) -> Self
[src]
fn from(user: &'a CurrentUser) -> Self
Performs the conversion.
impl From<User> for UserId
[src]
impl From<User> for UserId
impl<'a> From<&'a User> for UserId
[src]
impl<'a> From<&'a User> for UserId
impl Clone for User
[src]
impl Clone for User
fn clone(&self) -> User
[src]
fn clone(&self) -> User
Returns a copy of the value. Read more
fn clone_from(&mut self, source: &Self)
1.0.0[src]
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from source
. Read more
impl Eq for User
[src]
impl Eq for User
impl Debug for User
[src]
impl Debug for User
fn fmt(&self, f: &mut Formatter) -> Result
[src]
fn fmt(&self, f: &mut Formatter) -> Result
Formats the value using the given formatter. Read more
impl Display for User
[src]
impl Display for User
impl Hash for User
[src]
impl Hash for User
fn hash<H: Hasher>(&self, hasher: &mut H)
[src]
fn hash<H: Hasher>(&self, hasher: &mut H)
Feeds this value into the given [Hasher
]. Read more
fn hash_slice<H>(data: &[Self], state: &mut H) where
H: Hasher,
1.3.0[src]
fn hash_slice<H>(data: &[Self], state: &mut H) where
H: Hasher,
Feeds a slice of this type into the given [Hasher
]. Read more
impl FromStr for User
[src]
impl FromStr for User
type Err = UserParseError
The associated error which can be returned from parsing.
fn from_str(s: &str) -> StdResult<Self, Self::Err>
[src]
fn from_str(s: &str) -> StdResult<Self, Self::Err>
Parses a string s
to return a value of this type. Read more
impl Serialize for User
[src]
impl Serialize for User
fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error> where
__S: Serializer,
[src]
fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error> where
__S: Serializer,
Serialize this value into the given Serde serializer. Read more
impl<'de> Deserialize<'de> for User
[src]
impl<'de> Deserialize<'de> for User
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error> where
__D: Deserializer<'de>,
[src]
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error> where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
Auto Trait Implementations
Blanket Implementations
impl<T, U> Into for T where
U: From<T>,
[src]
impl<T, U> Into for T where
U: From<T>,
impl<T> ToString for T where
T: Display + ?Sized,
[src]
impl<T> ToString for T where
T: Display + ?Sized,
impl<T> ToOwned for T where
T: Clone,
[src]
impl<T> ToOwned for T where
T: Clone,
type Owned = T
fn to_owned(&self) -> T
[src]
fn to_owned(&self) -> T
Creates owned data from borrowed data, usually by cloning. Read more
fn clone_into(&self, target: &mut T)
[src]
fn clone_into(&self, target: &mut T)
🔬 This is a nightly-only experimental API. (toowned_clone_into
)
recently added
Uses borrowed data to replace owned data, usually by cloning. Read more
impl<T> From for T
[src]
impl<T> From for T
impl<T, U> TryFrom for T where
T: From<U>,
[src]
impl<T, U> TryFrom for T where
T: From<U>,
type Error = !
try_from
)The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
try_from
)Performs the conversion.
impl<T> Borrow for T where
T: ?Sized,
[src]
impl<T> Borrow for T where
T: ?Sized,
impl<T> BorrowMut for T where
T: ?Sized,
[src]
impl<T> BorrowMut for T where
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
impl<T, U> TryInto for T where
U: TryFrom<T>,
[src]
impl<T, U> TryInto for T where
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
try_from
)The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
try_from
)Performs the conversion.
impl<T> Any for T where
T: 'static + ?Sized,
[src]
impl<T> Any for T where
T: 'static + ?Sized,
fn get_type_id(&self) -> TypeId
[src]
fn get_type_id(&self) -> TypeId
🔬 This is a nightly-only experimental API. (get_type_id
)
this method will likely be replaced by an associated static
Gets the TypeId
of self
. Read more
impl<T> DeserializeOwned for T where
T: Deserialize<'de>,
[src]
impl<T> DeserializeOwned for T where
T: Deserialize<'de>,
impl<T> Erased for T
impl<T> Erased for T
impl<T> Typeable for T where
T: Any,
impl<T> Typeable for T where
T: Any,
impl<T> DebugAny for T where
T: Any + Debug,
[src]
impl<T> DebugAny for T where
T: Any + Debug,
impl<T> CloneAny for T where
T: Clone + Any,
[src]
impl<T> CloneAny for T where
T: Clone + Any,
fn clone_any(&self) -> Box<dyn CloneAny + 'static>
[src]
fn clone_any(&self) -> Box<dyn CloneAny + 'static>
fn clone_any_send(&self) -> Box<dyn CloneAny + 'static + Send> where
T: Send,
[src]
fn clone_any_send(&self) -> Box<dyn CloneAny + 'static + Send> where
T: Send,
fn clone_any_sync(&self) -> Box<dyn CloneAny + 'static + Sync> where
T: Sync,
[src]
fn clone_any_sync(&self) -> Box<dyn CloneAny + 'static + Sync> where
T: Sync,
fn clone_any_send_sync(&self) -> Box<dyn CloneAny + 'static + Sync + Send> where
T: Send + Sync,
[src]
fn clone_any_send_sync(&self) -> Box<dyn CloneAny + 'static + Sync + Send> where
T: Send + Sync,
impl<T> UnsafeAny for T where
T: Any,
impl<T> UnsafeAny for T where
T: Any,