Struct serenity::model::User [] [src]

pub struct User {
    pub id: UserId,
    pub avatar: Option<String>,
    pub bot: bool,
    pub discriminator: String,
    pub name: String,
}

Information about a user.

Fields

The unique Id of the user. Can be used to calculate the account's creation date.

Optional avatar hash.

Lets you know if the account is a bot or not.

The account's discriminator. The name + discriminator pair is always unique.

The account's username. Changing username will trigger a discriminator change if the pair is not unique.

Methods

impl User
[src]

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.

Creates a direct message channel between the current user and the user. This can also retrieve the channel if one already exists.

Returns the DiscordTag of a User.

Retrieves the time that this user was created at.

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

This will produce a PNG URL.

Errors

Returns an Error::Num if there was an error parsing the discriminator. Theoretically this is not possible.

Returns an Error::Other if the remainder of the calculation discriminator % 5 can not be matched. This is also probably not going to occur.

Deletes a profile note from a user.

Examples

Delete a note for a Message's author:

// assuming you are in a context

let _ = message.author.delete_note();

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

Sending a message:

// assuming you are in a context

let _ = message.author.direct_message("Hello!");

This is an alias of direct_message.

Examples

Sending a message:

// assuming you are in a context

let _ = message.author.dm("Hello!");

Edits the note that the current user has set for another user.

Use delete_note to remove a note.

Note: Requires that the current user be a user account.

Examples

Set a note for a message's author:

// assuming a `message` has been bound

let _ = message.author.edit_note("test note");

Errors

If the cache is enabled, returns a ClientError::InvalidOperationAsBot if the current user is a bot user.

Gets a user by its Id over the REST API.

Note: The current user must be a bot user.

Errors

If the cache is enabled, returns a ClientError::InvalidOperationAsUser if the current user is not a bot user.

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.

Three forms of data may be passed in to the guild parameter: either a Guild itself, a GuildId, or a u64.

Examples

Check if a guild has a Role by Id:

// Assumes a 'guild' and `role_id` have already been bound
let _ = message.author.has_role(guild, role_id);

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

This will always produce a WEBP image URL.

Trait Implementations

impl Mentionable for User
[src]

impl FromStr for User
[src]

The associated error which can be returned from parsing.

Parses a string s to return a value of this type. Read more

impl Display for User
[src]

Formats a string which will mention the user.

impl Clone for User
[src]

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

impl Debug for User
[src]

Formats the value using the given formatter.