[−][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]
pub fn avatar_url(&self) -> Option<String>
[src]
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,
http: impl AsRef<Http>
) -> Result<PrivateChannel>
[src]
&self,
http: impl AsRef<Http>
) -> 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) -> DateTime<FixedOffset>
[src]
Retrieves the time that this user was created at.
pub fn default_avatar_url(&self) -> String
[src]
Returns the formatted URL to the user's default avatar URL.
This will produce a PNG URL.
pub fn direct_message<F>(
&self,
cache_http: impl CacheHttp,
f: F
) -> Result<Message> where
F: FnOnce(&'b mut CreateMessage<'a>) -> &'b mut CreateMessage<'a>,
[src]
&self,
cache_http: impl CacheHttp,
f: F
) -> Result<Message> where
F: FnOnce(&'b mut CreateMessage<'a>) -> &'b mut CreateMessage<'a>,
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; struct Handler; impl EventHandler for Handler { fn message(&self, ctx: Context, msg: Message) { if msg.content == "~help" { let url = match ctx.cache.read().user.invite_url(&ctx, 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, ); let dm = msg.author.direct_message(&ctx, |m| { m.content(&help) }); match dm { Ok(_) => { let _ = msg.react(&ctx, '👌'); }, Err(why) => { println!("Err sending help: {:?}", why); let _ = msg.reply(&ctx, "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>(&self, cache_http: impl CacheHttp, f: F) -> Result<Message> where
F: FnOnce(&'b mut CreateMessage<'a>) -> &'b mut CreateMessage<'a>,
[src]
F: FnOnce(&'b mut CreateMessage<'a>) -> &'b mut CreateMessage<'a>,
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]
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,
cache_http: impl CacheHttp,
guild: G,
role: R
) -> Result<bool> where
G: Into<GuildContainer>,
R: Into<RoleId>,
[src]
&self,
cache_http: impl CacheHttp,
guild: G,
role: R
) -> Result<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, cache_http: impl CacheHttp) -> Result<()>
[src]
Refreshes the information about the user.
Replaces the instance with the data retrieved over the REST API.
pub fn static_avatar_url(&self) -> Option<String>
[src]
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]
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: 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(&context.http, &content); } } } let mut client = Client::new("token", Handler).unwrap(); client.start().unwrap();
pub fn nick_in<G>(
&self,
cache_http: impl CacheHttp,
guild_id: G
) -> Option<String> where
G: Into<GuildId>,
[src]
&self,
cache_http: impl CacheHttp,
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 Eq for User
[src]
impl Clone for User
[src]
impl PartialEq<User> for User
[src]
impl From<CurrentUser> for User
[src]
fn from(user: CurrentUser) -> Self
[src]
impl<'a> From<&'a CurrentUser> for User
[src]
fn from(user: &'a CurrentUser) -> Self
[src]
impl From<User> for UserId
[src]
impl<'a> From<&'a User> for UserId
[src]
impl Hash for User
[src]
fn hash<H: Hasher>(&self, hasher: &mut H)
[src]
fn hash_slice<H>(data: &[Self], state: &mut H) where
H: Hasher,
1.3.0[src]
H: Hasher,
impl Debug for User
[src]
impl Display for User
[src]
impl Serialize for User
[src]
fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error> where
__S: Serializer,
[src]
__S: Serializer,
impl<'de> Deserialize<'de> for User
[src]
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error> where
__D: Deserializer<'de>,
[src]
__D: Deserializer<'de>,
Auto Trait Implementations
impl Send for User
impl Unpin for User
impl Sync for User
impl UnwindSafe for User
impl RefUnwindSafe for User
Blanket Implementations
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
fn to_owned(&self) -> T
[src]
fn clone_into(&self, target: &mut T)
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> From<T> for T
[src]
impl<T> ToString for T where
T: Display + ?Sized,
[src]
T: Display + ?Sized,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> DeserializeOwned for T where
T: Deserialize<'de>,
[src]
T: Deserialize<'de>,
impl<T> Same<T> for T
type Output = T
Should always be Self
impl<Q, K> Equivalent<K> for Q where
K: Borrow<Q> + ?Sized,
Q: Eq + ?Sized,
[src]
K: Borrow<Q> + ?Sized,
Q: Eq + ?Sized,
fn equivalent(&self, key: &K) -> bool
[src]
impl<T> Erased for T
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
U: TryFrom<T>,
impl<T> DebugAny for T where
T: Any + Debug,
[src]
T: Any + Debug,
impl<T> CloneAny for T where
T: Clone + Any,
[src]
T: Clone + Any,
fn clone_any(&self) -> Box<dyn CloneAny + 'static>
[src]
fn clone_any_send(&self) -> Box<dyn CloneAny + 'static + Send> where
T: Send,
[src]
T: Send,
fn clone_any_sync(&self) -> Box<dyn CloneAny + 'static + Sync> where
T: Sync,
[src]
T: Sync,
fn clone_any_send_sync(&self) -> Box<dyn CloneAny + 'static + Sync + Send> where
T: Send + Sync,
[src]
T: Send + Sync,
impl<T> UnsafeAny for T where
T: Any,
T: Any,
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
V: MultiLane<T>,