Skip to content

Commit 4224b93

Browse files
committed
discord: Add User.DisplayOr{Username,Tag}
1 parent 2b0395a commit 4224b93

File tree

1 file changed

+18
-2
lines changed

1 file changed

+18
-2
lines changed

discord/user.go

+18-2
Original file line numberDiff line numberDiff line change
@@ -43,13 +43,29 @@ func (u User) Mention() string {
4343

4444
// Tag returns a tag of the user.
4545
func (u User) Tag() string {
46-
if u.Discriminator == "0" {
46+
if u.Discriminator == "0" || u.Discriminator == "0000" {
4747
return u.Username
4848
}
49-
5049
return u.Username + "#" + u.Discriminator
5150
}
5251

52+
// DisplayOrUsername returns the DisplayName if it is set, otherwise the
53+
// Username.
54+
func (u User) DisplayOrUsername() string {
55+
if u.DisplayName != "" {
56+
return u.DisplayName
57+
}
58+
return u.Username
59+
}
60+
61+
// DisplayOrTag returns the DisplayName if it is set, otherwise the Tag.
62+
func (u User) DisplayOrTag() string {
63+
if u.DisplayName != "" {
64+
return u.DisplayName
65+
}
66+
return u.Tag()
67+
}
68+
5369
// AvatarURL returns the URL of the Avatar Image. It automatically detects a
5470
// suitable type.
5571
func (u User) AvatarURL() string {

0 commit comments

Comments
 (0)