diff --git a/discord/cdn_endpoints.go b/discord/cdn_endpoints.go index 3b1a7ca3..597d3293 100644 --- a/discord/cdn_endpoints.go +++ b/discord/cdn_endpoints.go @@ -28,6 +28,7 @@ var ( ChannelIcon = NewCDN("/channel-icons/{channel.id}/{channel.icon.hash}", FileFormatPNG, FileFormatJPEG, FileFormatWebP) MemberAvatar = NewCDN("/guilds/{guild.id}/users/{user.id}/avatars/{member.avatar.hash}", FileFormatPNG, FileFormatJPEG, FileFormatWebP, FileFormatGIF) + MemberBanner = NewCDN("/guilds/{guild.id}/users/{user.id}/banners/{member.avatar.hash}", FileFormatPNG, FileFormatJPEG, FileFormatWebP, FileFormatGIF) AvatarDecoration = NewCDN("/avatar-decoration-presets/{user.avatar.decoration.hash}", FileFormatPNG) diff --git a/discord/member.go b/discord/member.go index 2bf9278f..f6bd33ce 100644 --- a/discord/member.go +++ b/discord/member.go @@ -16,6 +16,7 @@ type Member struct { User User `json:"user"` Nick *string `json:"nick"` Avatar *string `json:"avatar"` + Banner *string `json:"banner"` RoleIDs []snowflake.ID `json:"roles,omitempty"` JoinedAt time.Time `json:"joined_at"` PremiumSince *time.Time `json:"premium_since,omitempty"` @@ -53,10 +54,7 @@ func (m Member) EffectiveAvatarURL(opts ...CDNOpt) string { if m.Avatar == nil { return m.User.EffectiveAvatarURL(opts...) } - if avatar := m.AvatarURL(opts...); avatar != nil { - return *avatar - } - return "" + return formatAssetURL(MemberAvatar, opts, m.GuildID, m.User.ID, *m.Avatar) } // AvatarURL returns the guild-specific avatar URL of the user if set or nil @@ -68,6 +66,26 @@ func (m Member) AvatarURL(opts ...CDNOpt) *string { return &url } +// EffectiveBannerURL returns the guild-specific banner URL of the user if set, falling back to the banner URL of the user +func (m Member) EffectiveBannerURL(opts ...CDNOpt) string { + if m.Banner == nil { + if banner := m.User.BannerURL(opts...); banner != nil { + return *banner + } + return "" + } + return formatAssetURL(MemberBanner, opts, m.GuildID, m.User.ID, *m.Banner) +} + +// BannerURL returns the guild-specific banner URL of the user if set or nil +func (m Member) BannerURL(opts ...CDNOpt) *string { + if m.Banner == nil { + return nil + } + url := formatAssetURL(MemberBanner, opts, m.GuildID, m.User.ID, *m.Banner) + return &url +} + // AvatarDecorationURL returns the avatar decoration URL if set or nil func (m Member) AvatarDecorationURL(opts ...CDNOpt) *string { if m.AvatarDecorationData == nil { diff --git a/discord/user.go b/discord/user.go index 68f58f5d..bdf74c4f 100644 --- a/discord/user.go +++ b/discord/user.go @@ -106,10 +106,7 @@ func (u User) EffectiveAvatarURL(opts ...CDNOpt) string { if u.Avatar == nil { return u.DefaultAvatarURL(opts...) } - if avatar := u.AvatarURL(opts...); avatar != nil { - return *avatar - } - return "" + return formatAssetURL(UserAvatar, opts, u.ID, *u.Avatar) } // AvatarURL returns the avatar URL of the user if set or nil