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<(), Error>
Available on crate feature model only.
pub async fn edit( &mut self, cache_http: impl CacheHttp, builder: EditProfile, ) -> Result<(), Error>
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 = 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>
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.
Available on crate feature model only.
model only.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.
Sourcepub async fn create_dm_channel(
&self,
cache_http: impl CacheHttp,
) -> Result<PrivateChannel, Error>
Available on crate feature model only.
pub async fn create_dm_channel( &self, cache_http: impl CacheHttp, ) -> Result<PrivateChannel, Error>
model only.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
Available on crate feature model only.
pub fn created_at(&self) -> Timestamp
model only.Retrieves the time that this user was created at.
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 direct_message(
&self,
cache_http: impl CacheHttp,
builder: CreateMessage,
) -> Result<Message, Error>
Available on crate feature model only.
pub async fn direct_message( &self, cache_http: impl CacheHttp, builder: CreateMessage, ) -> Result<Message, Error>
model only.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
Available on crate feature model only.
pub fn display_name(&self) -> &str
model only.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, Error>
Available on crate feature model only.
pub async fn dm( &self, cache_http: impl CacheHttp, builder: CreateMessage, ) -> Result<Message, Error>
model only.This is an alias of Self::direct_message.
Sourcepub fn face(&self) -> String
Available on crate feature model only.
pub fn face(&self) -> String
model only.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
Available on crate feature model only.
pub fn static_face(&self) -> String
model only.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, Error>
Available on crate feature model only.
pub async fn has_role( &self, cache_http: impl CacheHttp, guild_id: impl Into<GuildId>, role: impl Into<RoleId>, ) -> Result<bool, Error>
model only.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<(), Error>
Available on crate feature model only.
pub async fn refresh(&mut self, cache_http: impl CacheHttp) -> Result<(), Error>
model only.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>
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.
Sourcepub fn tag(&self) -> String
Available on crate feature model only.
pub fn tag(&self) -> String
model only.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>
Available on crate feature model only.
pub async fn nick_in( &self, cache_http: impl CacheHttp, guild_id: impl Into<GuildId>, ) -> Option<String>
model only.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
Available on crate features model and collector only.
pub fn await_reply( &self, shard_messenger: impl AsRef<ShardMessenger>, ) -> MessageCollector
model and collector only.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
Available on crate features model and collector only.
pub fn await_replies( &self, shard_messenger: impl AsRef<ShardMessenger>, ) -> MessageCollector
model and collector only.Same as Self::await_reply.
Sourcepub fn await_reaction(
&self,
shard_messenger: impl AsRef<ShardMessenger>,
) -> ReactionCollector
Available on crate features model and collector only.
pub fn await_reaction( &self, shard_messenger: impl AsRef<ShardMessenger>, ) -> ReactionCollector
model and collector only.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
Available on crate features model and collector only.
pub fn await_reactions( &self, shard_messenger: impl AsRef<ShardMessenger>, ) -> ReactionCollector
model and collector only.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