[−][src]Struct serenity::model::user::CurrentUser
Information about the current user.
Fields
id: UserId
avatar: Option<String>
bot: bool
discriminator: u16
email: Option<String>
mfa_enabled: bool
name: String
verified: bool
Methods
impl CurrentUser
[src]
impl CurrentUser
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.
Examples
Print out the current user's avatar url if one is set:
// assuming the cache has been unlocked let user = &cache.user; match user.avatar_url() { Some(url) => println!("{}'s avatar can be found at {}", user.name, url), None => println!("{} does not have an avatar set.", user.name) }
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 edit<F>(&mut self, f: F) -> Result<()> where
F: FnOnce(EditProfile) -> EditProfile,
[src]
pub fn edit<F>(&mut self, f: F) -> Result<()> where
F: FnOnce(EditProfile) -> EditProfile,
Edits the current user's profile settings.
This mutates the current user in-place.
Refer to EditProfile
's documentation for its methods.
Examples
Change the avatar:
use serenity::CACHE; let avatar = serenity::utils::read_image("./avatar.png").unwrap(); CACHE.write().user.edit(|p| p.avatar(Some(&avatar)));
pub fn face(&self) -> String
[src]
pub fn face(&self) -> String
Retrieves the URL to the current 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 guilds(&self) -> Result<Vec<GuildInfo>>
[src]
pub fn guilds(&self) -> Result<Vec<GuildInfo>>
Gets a list of guilds that the current user is in.
Examples
Print out the names of all guilds the current user is in:
// assuming the cache has been unlocked let user = &cache.user; if let Ok(guilds) = user.guilds() { for (index, guild) in guilds.into_iter().enumerate() { println!("{}: {}", index, guild.name); } }
pub fn invite_url(&self, permissions: Permissions) -> Result<String>
[src]
pub fn invite_url(&self, permissions: Permissions) -> Result<String>
Returns the invite url for the bot with the given permissions.
This queries the REST API for the client id.
If the permissions passed are empty, the permissions part will be dropped.
Examples
Get the invite url with no permissions set:
use serenity::model::Permissions; // assuming the cache has been unlocked let url = match cache.user.invite_url(Permissions::empty()) { Ok(v) => v, Err(why) => { println!("Error getting invite url: {:?}", why); return; }, }; assert_eq!(url, "https://discordapp.com/api/oauth2/authorize? \ client_id=249608697955745802&scope=bot");
Get the invite url with some basic permissions set:
use serenity::model::Permissions; // assuming the cache has been unlocked let url = match cache.user.invite_url(Permissions::READ_MESSAGES | Permissions::SEND_MESSAGES | Permissions::EMBED_LINKS) { Ok(v) => v, Err(why) => { println!("Error getting invite url: {:?}", why); return; }, }; assert_eq!(url, "https://discordapp. com/api/oauth2/authorize?client_id=249608697955745802&scope=bot&permissions=19456");
Errors
Returns an
HttpError::UnsuccessfulRequest(Unauthorized)
If the user is not authorized for this end point.
May return Error::Format
while writing url to the buffer.
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.
Examples
Print out the current user's static avatar url if one is set:
// assuming the cache has been unlocked let user = &cache.user; match user.static_avatar_url() { Some(url) => println!("{}'s static avatar can be found at {}", user.name, url), None => println!("Could not get static avatar for {}.", user.name) }
pub fn tag(&self) -> String
[src]
pub fn tag(&self) -> String
Returns the tag of the current user.
Examples
Print out the current user's distinct identifier (e.g., Username#1234):
// assuming the cache has been unlocked println!("The current user's distinct identifier is {}", cache.user.tag());
Trait Implementations
impl Mentionable for CurrentUser
[src]
impl Mentionable for CurrentUser
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 Default for CurrentUser
[src]
impl Default for CurrentUser
fn default() -> CurrentUser
[src]
fn default() -> CurrentUser
Returns the "default value" for a type. Read more
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<CurrentUser> for UserId
[src]
impl From<CurrentUser> for UserId
fn from(current_user: CurrentUser) -> UserId
[src]
fn from(current_user: CurrentUser) -> UserId
Gets the Id of a CurrentUser
struct.
impl<'a> From<&'a CurrentUser> for UserId
[src]
impl<'a> From<&'a CurrentUser> for UserId
fn from(current_user: &CurrentUser) -> UserId
[src]
fn from(current_user: &CurrentUser) -> UserId
Gets the Id of a CurrentUser
struct.
impl Clone for CurrentUser
[src]
impl Clone for CurrentUser
fn clone(&self) -> CurrentUser
[src]
fn clone(&self) -> CurrentUser
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 Debug for CurrentUser
[src]
impl Debug for CurrentUser
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 Serialize for CurrentUser
[src]
impl Serialize for CurrentUser
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 CurrentUser
[src]
impl<'de> Deserialize<'de> for CurrentUser
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
impl Send for CurrentUser
impl Send for CurrentUser
impl Sync for CurrentUser
impl Sync for CurrentUser
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> 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,