user.go 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. package discordgo
  2. import "strings"
  3. // A User stores all data for an individual Discord user.
  4. type User struct {
  5. ID string `json:"id"`
  6. Email string `json:"email"`
  7. Username string `json:"username"`
  8. Avatar string `json:"avatar"`
  9. Discriminator string `json:"discriminator"`
  10. Token string `json:"token"`
  11. Verified bool `json:"verified"`
  12. MFAEnabled bool `json:"mfa_enabled"`
  13. Bot bool `json:"bot"`
  14. }
  15. // String returns a unique identifier of the form username#discriminator
  16. func (u *User) String() string {
  17. return u.Username + "#" + u.Discriminator
  18. }
  19. // Mention return a string which mentions the user
  20. func (u *User) Mention() string {
  21. return "<@" + u.ID + ">"
  22. }
  23. // AvatarURL returns a URL to the user's avatar.
  24. // size: The size of the user's avatar as a power of two
  25. func (u *User) AvatarURL(size string) string {
  26. var URL string
  27. if strings.HasPrefix(u.Avatar, "a_") {
  28. URL = EndpointUserAvatarAnimated(u.ID, u.Avatar)
  29. } else {
  30. URL = EndpointUserAvatar(u.ID, u.Avatar)
  31. }
  32. return URL + "?size=" + size
  33. }