pub struct CurrentUser(/* private fields */);Expand description
Information about the current user.
Implementations§
Source§impl CurrentUser
impl CurrentUser
Sourcepub async fn edit(
&mut self,
cache_http: impl CacheHttp,
builder: EditProfile,
) -> Result<()>
pub async fn edit( &mut self, cache_http: impl CacheHttp, builder: EditProfile, ) -> Result<()>
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 = CreateAttachment::path("./avatar.png").await?;
user.edit(&http, EditProfile::new().avatar(&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.
Methods from Deref<Target = User>§
Sourcepub fn avatar_url(&self) -> Option<String>
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.
Returns the formatted URL of the user’s banner, if one exists.
This will produce a WEBP image URL, or GIF if the user has a GIF banner.
Note: This will only be present if the user is fetched via Rest API, e.g. with
crate::http::Http::get_user.
Sourcepub async fn create_dm_channel(
&self,
cache_http: impl CacheHttp,
) -> Result<PrivateChannel>
pub async fn create_dm_channel( &self, cache_http: impl CacheHttp, ) -> Result<PrivateChannel>
Creates a direct message channel between the current user and the user. This can also retrieve the channel if one already exists.
§Errors
See UserId::create_dm_channel for what errors may be returned.
Sourcepub fn created_at(&self) -> Timestamp
pub fn created_at(&self) -> Timestamp
Retrieves the time that this user was created at.
Sourcepub fn default_avatar_url(&self) -> String
pub fn default_avatar_url(&self) -> String
Returns the formatted URL to the user’s default avatar URL.
This will produce a PNG URL.
Sourcepub async fn direct_message(
&self,
cache_http: impl CacheHttp,
builder: CreateMessage,
) -> Result<Message>
pub async fn direct_message( &self, cache_http: impl CacheHttp, builder: CreateMessage, ) -> Result<Message>
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
See UserId::direct_message for examples.
§Errors
See UserId::direct_message for errors.
Sourcepub fn display_name(&self) -> &str
pub fn display_name(&self) -> &str
Calculates the user’s display name.
The global name takes priority over the user’s username if it exists.
Note: Guild specific information is not included as this is only available on the Member.
Sourcepub async fn dm(
&self,
cache_http: impl CacheHttp,
builder: CreateMessage,
) -> Result<Message>
pub async fn dm( &self, cache_http: impl CacheHttp, builder: CreateMessage, ) -> Result<Message>
This is an alias of Self::direct_message.
Sourcepub fn face(&self) -> String
pub fn face(&self) -> String
Retrieves the URL to the 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 fn static_face(&self) -> String
pub fn static_face(&self) -> String
Retrieves the URL to the static version of the user’s avatar, falling back to the default avatar if needed.
This will call Self::static_avatar_url first, and if that returns None, it then
falls back to Self::default_avatar_url.
Sourcepub async fn has_role(
&self,
cache_http: impl CacheHttp,
guild_id: impl Into<GuildId>,
role: impl Into<RoleId>,
) -> Result<bool>
pub async fn has_role( &self, cache_http: impl CacheHttp, guild_id: impl Into<GuildId>, role: impl Into<RoleId>, ) -> Result<bool>
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.
§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);§Errors
Returns an Error::Http if the given Guild is unavailable, if that Role does not
exist in the given Guild, or if the given User is not in that Guild.
May also return an Error::Json if there is an error in deserializing the API response.
Sourcepub async fn refresh(&mut self, cache_http: impl CacheHttp) -> Result<()>
pub async fn refresh(&mut self, cache_http: impl CacheHttp) -> Result<()>
Refreshes the information about the user.
Replaces the instance with the data retrieved over the REST API.
§Errors
See UserId::to_user for what errors may be returned.
Sourcepub fn static_avatar_url(&self) -> Option<String>
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.
Sourcepub fn tag(&self) -> String
pub fn tag(&self) -> String
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:
#[serenity::async_trait]
impl EventHandler for Handler {
async fn message(&self, context: Context, msg: Message) {
if msg.content == "!mytag" {
let content = format!("Your tag is: {}", msg.author.tag());
let _ = msg.channel_id.say(&context.http, &content).await;
}
}
}Sourcepub async fn nick_in(
&self,
cache_http: impl CacheHttp,
guild_id: impl Into<GuildId>,
) -> Option<String>
pub async fn nick_in( &self, cache_http: impl CacheHttp, guild_id: impl Into<GuildId>, ) -> Option<String>
Returns the user’s nickname in the given guild_id.
If none is used, it returns None.
Sourcepub fn await_reply(
&self,
shard_messenger: impl AsRef<ShardMessenger>,
) -> MessageCollector
pub fn await_reply( &self, shard_messenger: impl AsRef<ShardMessenger>, ) -> MessageCollector
Returns a builder which can be awaited to obtain a message or stream of messages sent by this user.
Sourcepub fn await_replies(
&self,
shard_messenger: impl AsRef<ShardMessenger>,
) -> MessageCollector
pub fn await_replies( &self, shard_messenger: impl AsRef<ShardMessenger>, ) -> MessageCollector
Same as Self::await_reply.
Sourcepub fn await_reaction(
&self,
shard_messenger: impl AsRef<ShardMessenger>,
) -> ReactionCollector
pub fn await_reaction( &self, shard_messenger: impl AsRef<ShardMessenger>, ) -> ReactionCollector
Returns a builder which can be awaited to obtain a reaction or stream of reactions sent by this user.
Sourcepub fn await_reactions(
&self,
shard_messenger: impl AsRef<ShardMessenger>,
) -> ReactionCollector
pub fn await_reactions( &self, shard_messenger: impl AsRef<ShardMessenger>, ) -> ReactionCollector
Same as Self::await_reaction.
Trait Implementations§
Source§impl Clone for CurrentUser
impl Clone for CurrentUser
Source§fn clone(&self) -> CurrentUser
fn clone(&self) -> CurrentUser
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more