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

#[non_exhaustive]
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>, pub public_flags: Option<UserPublicFlags>, pub banner: Option<String>, pub accent_colour: Option<Colour>, }
Expand description

Information about the current user.

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: UserIdavatar: Option<String>bot: booldiscriminator: u16email: Option<String>mfa_enabled: boolname: Stringverified: Option<bool>public_flags: Option<UserPublicFlags>banner: Option<String>accent_colour: Option<Colour>

Implementations

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.current_user().await;

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),
}

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

This will produce a PNG URL.

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:

let avatar = serenity::utils::read_image("./avatar.png")?;

user.edit(&http, |p| p.avatar(Some(&avatar))).await;
Errors

Returns an Error::Http if an invalid value is set. May also return an Error::Json if there is an error in deserializing the API response.

Retrieves the URL to the current 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.

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 user has been bound

if let Ok(guilds) = user.guilds(&http).await {
    for (index, guild) in guilds.into_iter().enumerate() {
        println!("{}: {}", index, guild.name);
    }
}
Errors

May return an Error::Http if the Discord API returns an error. Also can return Error::Json if there is an error in deserializing the data returned by the API.

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.

Only the bot scope is used, if you wish to use more, such as slash commands, see Self::invite_url_with_oauth2_scopes

Examples

Get the invite url with no permissions set:

use serenity::model::Permissions;

// assuming the user has been bound
let url = match user.invite_url(&http, Permissions::empty()).await {
    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 user has been bound
let permissions =
    Permissions::READ_MESSAGES | Permissions::SEND_MESSAGES | Permissions::EMBED_LINKS;
let url = match user.invite_url(&http, permissions).await {
    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.

Should never return Error::Url as all the data is controlled over.

Generate an invite url, but with custom scopes.

Examples

Get the invite url with no permissions set and slash commands support:

use serenity::model::oauth2::OAuth2Scope;
use serenity::model::Permissions;

let scopes = vec![OAuth2Scope::Bot, OAuth2Scope::ApplicationsCommands];

// assuming the user has been bound
let url = match user.invite_url_with_oauth2_scopes(&http, Permissions::empty(), &scopes).await {
    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%20applications.commands"
);
Errors

Returns an HttpError::UnsuccessfulRequest(Unauthorized) If the user is not authorized for this end point.

Should never return Error::Url as all the data is controlled over.

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 user has been bound

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),
}

Returns the tag of the current user.

Examples

Print out the current user’s distinct identifier (e.g., Username#1234):

// assuming the user has been bound

println!("The current user's distinct identifier is {}", user.tag());

Trait Implementations

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

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

Deserialize this value from the given Serde deserializer. Read more

Performs the conversion.

Performs the conversion.

Gets the Id of a CurrentUser struct.

Performs the conversion.

Gets the Id of a CurrentUser struct.

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

Serialize this value into the given Serde serializer. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

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

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

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

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

Performs the conversion.

Should always be Self

The resulting type after obtaining ownership.

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

🔬 This is a nightly-only experimental API. (toowned_clone_into)

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

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.

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

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