pub struct CurrentUser(/* private fields */);
Expand description

Information about the current user.

Discord docs.

Implementations§

source§

impl CurrentUser

source

pub async fn edit( &mut self, cache_http: impl CacheHttp, builder: EditProfile ) -> Result<()>

Available on crate feature 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>§

source

pub fn avatar_url(&self) -> Option<String>

Available on crate feature 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.

source

pub fn banner_url(&self) -> Option<String>

Available on crate feature 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.

Note: This will only be present if the user is fetched via Rest API, e.g. with crate::http::Http::get_user.

source

pub async fn create_dm_channel( &self, cache_http: impl CacheHttp ) -> Result<PrivateChannel>

Available on crate feature 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.

source

pub fn created_at(&self) -> Timestamp

Available on crate feature model only.

Retrieves the time that this user was created at.

source

pub fn default_avatar_url(&self) -> String

Available on crate feature model only.

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

This will produce a PNG URL.

source

pub async fn direct_message( &self, cache_http: impl CacheHttp, builder: CreateMessage ) -> Result<Message>

Available on crate feature 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

When a user sends a message with a content of "~help", DM the author a help message

use serenity::builder::CreateMessage;

#[serenity::async_trait]
impl EventHandler for Handler {
    async fn message(&self, ctx: Context, msg: Message) {
        if msg.content == "~help" {
            let builder = CreateMessage::new().content("Helpful info here.");

            if let Err(why) = msg.author.direct_message(&ctx, builder).await {
                println!("Err sending help: {why:?}");
                let _ = msg.reply(&ctx, "There was an error DMing you help.").await;
            };
        }
    }
}
§Errors

Returns a ModelError::MessagingBot if the user being direct messaged is a bot user.

May also return an Error::Http if the user cannot be sent a direct message.

Returns an Error::Json if there is an error deserializing the API response.

source

pub async fn dm( &self, cache_http: impl CacheHttp, builder: CreateMessage ) -> Result<Message>

Available on crate feature model only.

This is an alias of Self::direct_message.

source

pub fn face(&self) -> String

Available on crate feature 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.

source

pub fn static_face(&self) -> String

Available on crate feature 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.

source

pub async fn has_role( &self, cache_http: impl CacheHttp, guild_id: impl Into<GuildId>, role: impl Into<RoleId> ) -> Result<bool>

Available on crate feature 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.

source

pub async fn refresh(&mut self, cache_http: impl CacheHttp) -> Result<()>

Available on crate feature 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.

source

pub fn static_avatar_url(&self) -> Option<String>

Available on crate feature model only.

Returns a static formatted URL of the user’s icon, if one exists.

This will always produce a WEBP image URL.

source

pub fn tag(&self) -> String

Available on crate feature 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;
        }
    }
}
source

pub async fn nick_in( &self, cache_http: impl CacheHttp, guild_id: impl Into<GuildId> ) -> Option<String>

Available on crate feature model only.

Returns the user’s nickname in the given guild_id.

If none is used, it returns None.

source

pub fn await_reply( &self, shard_messenger: impl AsRef<ShardMessenger> ) -> MessageCollector

Available on crate features model and collector only.

Returns a builder which can be awaited to obtain a message or stream of messages sent by this user.

source

pub fn await_replies( &self, shard_messenger: impl AsRef<ShardMessenger> ) -> MessageCollector

Available on crate features model and collector only.
source

pub fn await_reaction( &self, shard_messenger: impl AsRef<ShardMessenger> ) -> ReactionCollector

Available on crate features model and collector only.

Returns a builder which can be awaited to obtain a reaction or stream of reactions sent by this user.

source

pub fn await_reactions( &self, shard_messenger: impl AsRef<ShardMessenger> ) -> ReactionCollector

Available on crate features model and collector only.

Trait Implementations§

source§

impl Clone for CurrentUser

source§

fn clone(&self) -> CurrentUser

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for CurrentUser

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl Default for CurrentUser

source§

fn default() -> CurrentUser

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

impl Deref for CurrentUser

§

type Target = User

The resulting type after dereferencing.
source§

fn deref(&self) -> &Self::Target

Dereferences the value.
source§

impl DerefMut for CurrentUser

source§

fn deref_mut(&mut self) -> &mut Self::Target

Mutably dereferences the value.
source§

impl<'de> Deserialize<'de> for CurrentUser

source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
source§

impl From<CurrentUser> for User

source§

fn from(user: CurrentUser) -> Self

Converts to this type from the input type.
source§

impl Mentionable for CurrentUser

source§

fn mention(&self) -> Mention

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

impl Serialize for CurrentUser

source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> CloneDebuggableStorage for T

source§

impl<T> CloneableStorage for T
where T: Any + Send + Sync + Clone,

source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T> Instrument for T

source§

fn instrument(self, span: Span) -> Instrumented<Self>

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

fn in_current_span(self) -> Instrumented<Self>

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

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> Same for T

§

type Output = T

Should always be Self
source§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

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

fn clone_into(&self, target: &mut T)

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

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

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

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

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

§

fn vzip(self) -> V

source§

impl<T> WithSubscriber for T

source§

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
source§

fn with_current_subscriber(self) -> WithDispatch<Self>

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

impl<T> DebuggableStorage for T
where T: Any + Send + Sync + Debug,

source§

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