[][src]Struct serenity::model::user::CurrentUser

pub struct CurrentUser {
    pub id: UserId,
    pub avatar: Option<String>,
    pub bot: bool,
    pub discriminator: u16,
    pub email: Option<String>,
    pub mfa_enabled: bool,
    pub name: String,
    pub verified: Option<bool>,
    // some fields omitted
}

Information about the current user.

Fields

id: UserIdavatar: Option<String>bot: booldiscriminator: u16email: Option<String>mfa_enabled: boolname: Stringverified: Option<bool>

Methods

impl CurrentUser[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.

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]

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

This will produce a PNG URL.

pub fn edit<F>(&mut self, http: impl AsRef<Http>, f: F) -> Result<()> where
    F: FnOnce(&mut EditProfile) -> &mut EditProfile
[src]

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:

This example is not tested
let avatar = serenity::utils::read_image("./avatar.png").unwrap();

context.cache.write().user.edit(|p| p.avatar(Some(&avatar)));

pub fn face(&self) -> String[src]

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, http: impl AsRef<Http>) -> Result<Vec<GuildInfo>>[src]

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(&http) {
    for (index, guild) in guilds.into_iter().enumerate() {
        println!("{}: {}", index, guild.name);
    }
}

pub fn invite_url(
    &self,
    http: impl AsRef<Http>,
    permissions: Permissions
) -> Result<String>
[src]

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(&http, 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(&http, 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]

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]

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 Clone for CurrentUser[src]

impl Debug for CurrentUser[src]

impl Default for CurrentUser[src]

impl<'de> Deserialize<'de> for CurrentUser[src]

impl<'a> From<&'a CurrentUser> for User[src]

impl<'a> From<&'a CurrentUser> for UserId[src]

fn from(current_user: &CurrentUser) -> UserId[src]

Gets the Id of a CurrentUser struct.

impl From<CurrentUser> for User[src]

impl From<CurrentUser> for UserId[src]

fn from(current_user: CurrentUser) -> UserId[src]

Gets the Id of a CurrentUser struct.

impl Mentionable for CurrentUser[src]

impl Serialize for CurrentUser[src]

Auto Trait Implementations

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> CloneAny for T where
    T: Clone + Any
[src]

impl<T> DebugAny for T where
    T: Any + Debug
[src]

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

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> Same<T> for T

type Output = T

Should always be Self

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.

impl<T> UnsafeAny for T where
    T: Any

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