feat: add guild member banners (#1592)

This commit is contained in:
Alex 2025-03-17 10:22:05 +01:00 committed by GitHub
parent 2d15f13e65
commit d4827e8d77
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 25 additions and 0 deletions

View file

@ -115,6 +115,12 @@ var (
EndpointGuildMemberAvatarAnimated = func(gId, uID, aID string) string {
return EndpointCDNGuilds + gId + "/users/" + uID + "/avatars/" + aID + ".gif"
}
EndpointGuildMemberBanner = func(gId, uID, hash string) string {
return EndpointCDNGuilds + gId + "/users/" + uID + "/banners/" + hash + ".png"
}
EndpointGuildMemberBannerAnimated = func(gId, uID, hash string) string {
return EndpointCDNGuilds + gId + "/users/" + uID + "/banners/" + hash + ".gif"
}
EndpointRoleIcon = func(rID, hash string) string {
return EndpointCDNRoleIcons + rID + "/" + hash + ".png"

View file

@ -1566,6 +1566,9 @@ type Member struct {
// The hash of the avatar for the guild member, if any.
Avatar string `json:"avatar"`
// The hash of the banner for the guild member, if any.
Banner string `json:"banner"`
// The underlying user on which the member is based.
User *User `json:"user"`
@ -1610,6 +1613,22 @@ func (m *Member) AvatarURL(size string) string {
}
// BannerURL returns the URL of the member's banner image.
//
// size: The size of the desired banner image as a power of two
// Image size can be any power of two between 16 and 4096.
func (m *Member) BannerURL(size string) string {
if m.Banner == "" {
return m.User.BannerURL(size)
}
return bannerURL(
m.Banner,
EndpointGuildMemberBanner(m.GuildID, m.User.ID, m.Banner),
EndpointGuildMemberBannerAnimated(m.GuildID, m.User.ID, m.Banner),
size,
)
}
// DisplayName returns the member's guild nickname if they have one,
// otherwise it returns their discord display name.
func (m *Member) DisplayName() string {