1package discordgo 2 3import "strings" 4 5// A User stores all data for an individual Discord user. 6type User struct { 7 // The ID of the user. 8 ID string `json:"id"` 9 10 // The email of the user. This is only present when 11 // the application possesses the email scope for the user. 12 Email string `json:"email"` 13 14 // The user's username. 15 Username string `json:"username"` 16 17 // The hash of the user's avatar. Use Session.UserAvatar 18 // to retrieve the avatar itself. 19 Avatar string `json:"avatar"` 20 21 // The user's chosen language option. 22 Locale string `json:"locale"` 23 24 // The discriminator of the user (4 numbers after name). 25 Discriminator string `json:"discriminator"` 26 27 // The token of the user. This is only present for 28 // the user represented by the current session. 29 Token string `json:"token"` 30 31 // Whether the user's email is verified. 32 Verified bool `json:"verified"` 33 34 // Whether the user has multi-factor authentication enabled. 35 MFAEnabled bool `json:"mfa_enabled"` 36 37 // Whether the user is a bot. 38 Bot bool `json:"bot"` 39} 40 41// String returns a unique identifier of the form username#discriminator 42func (u *User) String() string { 43 return u.Username + "#" + u.Discriminator 44} 45 46// Mention return a string which mentions the user 47func (u *User) Mention() string { 48 return "<@" + u.ID + ">" 49} 50 51// AvatarURL returns a URL to the user's avatar. 52// size: The size of the user's avatar as a power of two 53// if size is an empty string, no size parameter will 54// be added to the URL. 55func (u *User) AvatarURL(size string) string { 56 var URL string 57 if u.Avatar == "" { 58 URL = EndpointDefaultUserAvatar(u.Discriminator) 59 } else if strings.HasPrefix(u.Avatar, "a_") { 60 URL = EndpointUserAvatarAnimated(u.ID, u.Avatar) 61 } else { 62 URL = EndpointUserAvatar(u.ID, u.Avatar) 63 } 64 65 if size != "" { 66 return URL + "?size=" + size 67 } 68 return URL 69} 70