#[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
Struct { .. }
syntax; cannot be matched against without a wildcard ..
; and struct update syntax will not work.id: UserId
avatar: Option<String>
bot: bool
discriminator: u16
email: Option<String>
mfa_enabled: bool
name: String
verified: Option<bool>
public_flags: Option<UserPublicFlags>
accent_colour: Option<Colour>
utils
only.Implementations
sourceimpl CurrentUser
impl CurrentUser
sourcepub fn avatar_url(&self) -> Option<String>
Available on crate feature model
only.
pub fn avatar_url(&self) -> Option<String>
model
only.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();
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),
}
sourcepub fn default_avatar_url(&self) -> String
Available on crate feature model
only.
pub fn default_avatar_url(&self) -> String
model
only.Returns the formatted URL to the user’s default avatar URL.
This will produce a PNG URL.
sourcepub async fn edit<F>(&mut self, http: impl AsRef<Http>, f: F) -> Result<()> where
F: FnOnce(&mut EditProfile) -> &mut EditProfile,
Available on crate feature model
only.
pub async fn edit<F>(&mut self, http: impl AsRef<Http>, f: F) -> Result<()> where
F: FnOnce(&mut EditProfile) -> &mut EditProfile,
model
only.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.
sourcepub fn face(&self) -> String
Available on crate feature model
only.
pub fn face(&self) -> String
model
only.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
.
sourcepub async fn guilds(&self, http: impl AsRef<Http>) -> Result<Vec<GuildInfo>>
Available on crate feature model
only.
pub async fn guilds(&self, http: impl AsRef<Http>) -> Result<Vec<GuildInfo>>
model
only.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.
sourcepub async fn invite_url(
&self,
http: impl AsRef<Http>,
permissions: Permissions
) -> Result<String>
Available on crate feature model
only.
pub async fn invite_url(
&self,
http: impl AsRef<Http>,
permissions: Permissions
) -> Result<String>
model
only.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::VIEW_CHANNEL | 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.
sourcepub async fn invite_url_with_oauth2_scopes(
&self,
http: impl AsRef<Http>,
permissions: Permissions,
scopes: &[OAuth2Scope]
) -> Result<String>
Available on crate feature model
only.
pub async fn invite_url_with_oauth2_scopes(
&self,
http: impl AsRef<Http>,
permissions: Permissions,
scopes: &[OAuth2Scope]
) -> Result<String>
model
only.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.
sourcepub fn static_avatar_url(&self) -> Option<String>
Available on crate feature model
only.
pub fn static_avatar_url(&self) -> Option<String>
model
only.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),
}
Trait Implementations
sourceimpl Clone for CurrentUser
impl Clone for CurrentUser
sourcefn clone(&self) -> CurrentUser
fn clone(&self) -> CurrentUser
Returns a copy of the value. Read more
1.0.0 · sourcefn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from source
. Read more
sourceimpl Debug for CurrentUser
impl Debug for CurrentUser
sourceimpl Default for CurrentUser
impl Default for CurrentUser
sourcefn default() -> CurrentUser
fn default() -> CurrentUser
Returns the “default value” for a type. Read more
sourceimpl<'de> Deserialize<'de> for CurrentUser
impl<'de> Deserialize<'de> for CurrentUser
sourcefn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error> where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error> where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
sourceimpl<'a> From<&'a CurrentUser> for User
impl<'a> From<&'a CurrentUser> for User
sourcefn from(user: &'a CurrentUser) -> Self
fn from(user: &'a CurrentUser) -> Self
Converts to this type from the input type.
sourceimpl<'a> From<&'a CurrentUser> for UserId
impl<'a> From<&'a CurrentUser> for UserId
sourcefn from(current_user: &CurrentUser) -> UserId
fn from(current_user: &CurrentUser) -> UserId
Gets the Id of a CurrentUser
struct.
sourceimpl From<CurrentUser> for User
impl From<CurrentUser> for User
sourcefn from(user: CurrentUser) -> Self
fn from(user: CurrentUser) -> Self
Converts to this type from the input type.
sourceimpl From<CurrentUser> for UserId
impl From<CurrentUser> for UserId
sourcefn from(current_user: CurrentUser) -> UserId
fn from(current_user: CurrentUser) -> UserId
Gets the Id of a CurrentUser
struct.
sourceimpl Mentionable for CurrentUser
impl Mentionable for CurrentUser
sourceimpl Serialize for CurrentUser
impl Serialize for CurrentUser
Auto Trait Implementations
impl RefUnwindSafe for CurrentUser
impl Send for CurrentUser
impl Sync for CurrentUser
impl Unpin for CurrentUser
impl UnwindSafe for CurrentUser
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<T> Instrument for T
impl<T> Instrument for T
sourcefn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
sourcefn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
sourceimpl<T> ToOwned for T where
T: Clone,
impl<T> ToOwned for T where
T: Clone,
type Owned = T
type Owned = T
The resulting type after obtaining ownership.
sourcefn clone_into(&self, target: &mut T)
fn clone_into(&self, target: &mut T)
toowned_clone_into
)Uses borrowed data to replace owned data, usually by cloning. Read more
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
fn vzip(self) -> V
sourceimpl<T> WithSubscriber for T
impl<T> WithSubscriber for T
sourcefn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> where
S: Into<Dispatch>,
fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> where
S: Into<Dispatch>,
Attaches the provided Subscriber
to this type, returning a
WithDispatch
wrapper. Read more
sourcefn with_current_subscriber(self) -> WithDispatch<Self>
fn with_current_subscriber(self) -> WithDispatch<Self>
Attaches the current default Subscriber
to this type, returning a
WithDispatch
wrapper. Read more