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
id: UserId
The unique Id of the user. Can be used to calculate the account's creation date.
avatar: Option<String>
Optional avatar hash.
bot: bool
Lets you know if the account is a bot or not.
discriminator: String
The account's discriminator. The name + discriminator pair is always unique.
name: String
The account's username. Changing username will trigger a discriminator change if the pair is not unique.
Methods
impl User
[src]
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.
fn create_dm_channel(&self) -> Result<PrivateChannel>
Creates a direct message channel between the current user and the user. This can also retrieve the channel if one already exists.
fn distinct(&self) -> String
Returns the DiscordTag of a User.
fn created_at(&self) -> Timespec
Retrieves the time that this user was created at.
fn default_avatar_url(&self) -> Result<String>
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.
fn delete_note(&self) -> Result<()>
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();
fn direct_message(&self, content: &str) -> 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
Sending a message:
// assuming you are in a context let _ = message.author.direct_message("Hello!");
fn dm(&self, content: &str) -> Result<Message>
This is an alias of direct_message.
Examples
Sending a message:
// assuming you are in a context let _ = message.author.dm("Hello!");
fn edit_note(&self, note: &str) -> Result<()>
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.
fn get<U: Into<UserId>>(user_id: U) -> Result<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.
fn has_role<G, R>(&self, guild: G, role: R) -> bool where G: Into<GuildContainer>, R: Into<RoleId>
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);
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.
Trait Implementations
impl Mentionable for User
[src]
impl FromStr for User
[src]
type Err = ()
The associated error which can be returned from parsing.
fn from_str(s: &str) -> StdResult<Self, ()>
Parses a string s
to return a value of this type. Read more
impl Display for User
[src]
impl Clone for User
[src]
fn clone(&self) -> User
Returns a copy of the value. Read more
fn clone_from(&mut self, source: &Self)
1.0.0
Performs copy-assignment from source
. Read more