From 56632c6bb5dd0405008c6365a30fa8b1d5b5880a Mon Sep 17 00:00:00 2001 From: Jiralite <33201955+Jiralite@users.noreply.github.com> Date: Fri, 12 Jul 2024 07:14:50 +0100 Subject: [PATCH 1/4] feat: initial support for guild member banners --- .../discord.js/src/structures/GuildMember.js | 31 +++++++++++++++++++ packages/discord.js/typings/index.d.ts | 3 ++ 2 files changed, 34 insertions(+) diff --git a/packages/discord.js/src/structures/GuildMember.js b/packages/discord.js/src/structures/GuildMember.js index 2a39f3f59940..b9dc7935e6ce 100644 --- a/packages/discord.js/src/structures/GuildMember.js +++ b/packages/discord.js/src/structures/GuildMember.js @@ -84,6 +84,17 @@ class GuildMember extends Base { } else if (typeof this.avatar !== 'string') { this.avatar = null; } + + if ('banner' in data) { + /** + * The guild member's banner hash. + * @type {?string} + */ + this.banner = data.banner; + } else { + this.banner ??= null; + } + if ('joined_at' in data) this.joinedTimestamp = Date.parse(data.joined_at); if ('premium_since' in data) { this.premiumSinceTimestamp = data.premium_since ? Date.parse(data.premium_since) : null; @@ -155,6 +166,15 @@ class GuildMember extends Base { return this.avatar && this.client.rest.cdn.guildMemberAvatar(this.guild.id, this.id, this.avatar, options); } + /** + * A link to the member's banner. + * @param {ImageURLOptions} [options={}] Options for the banner URL + * @returns {?string} + */ + bannerURL(options = {}) { + return this.banner && this.client.rest.cdn.guildMemberBanner(this.guild.id, this.id, this.banner, options); + } + /** * A link to the member's guild avatar if they have one. * Otherwise, a link to their {@link User#displayAvatarURL} will be returned. @@ -165,6 +185,16 @@ class GuildMember extends Base { return this.avatarURL(options) ?? this.user.displayAvatarURL(options); } + /** + * A link to the member's guild banner if they have one. + * Otherwise, a link to their {@link User#bannerURL} will be returned. + * @param {ImageURLOptions} [options={}] Options for the Image URL + * @returns {?string} + */ + displayBannerURL(options) { + return this.bannerURL(options) ?? this.user.bannerURL(options); + } + /** * The time this member joined the guild * @type {?Date} @@ -464,6 +494,7 @@ class GuildMember extends Base { this.joinedTimestamp === member.joinedTimestamp && this.nickname === member.nickname && this.avatar === member.avatar && + this.banner === member.banner && this.pending === member.pending && this.communicationDisabledUntilTimestamp === member.communicationDisabledUntilTimestamp && this.flags.bitfield === member.flags.bitfield && diff --git a/packages/discord.js/typings/index.d.ts b/packages/discord.js/typings/index.d.ts index b1071e1d3558..7bba8185d864 100644 --- a/packages/discord.js/typings/index.d.ts +++ b/packages/discord.js/typings/index.d.ts @@ -1604,6 +1604,7 @@ export class GuildMember extends Base { private constructor(client: Client, data: RawGuildMemberData, guild: Guild); private _roles: Snowflake[]; public avatar: string | null; + public banner: string | null; public get bannable(): boolean; public get dmChannel(): DMChannel | null; public get displayColor(): number; @@ -1630,6 +1631,7 @@ export class GuildMember extends Base { public user: User; public get voice(): VoiceState; public avatarURL(options?: ImageURLOptions): string | null; + public bannerURL(options?: ImageURLOptions): string | null; public ban(options?: BanOptions): Promise; public disableCommunicationUntil(timeout: DateResolvable | null, reason?: string): Promise; public timeout(timeout: number | null, reason?: string): Promise; @@ -1637,6 +1639,7 @@ export class GuildMember extends Base { public createDM(force?: boolean): Promise; public deleteDM(): Promise; public displayAvatarURL(options?: ImageURLOptions): string; + public displayBannerURL(options?: ImageURLOptions): string | null; public edit(options: GuildMemberEditOptions): Promise; public isCommunicationDisabled(): this is GuildMember & { communicationDisabledUntilTimestamp: number; From 91a547e2662a684116d9846bde14544dad274f44 Mon Sep 17 00:00:00 2001 From: Jiralite <33201955+Jiralite@users.noreply.github.com> Date: Fri, 12 Jul 2024 07:18:05 +0100 Subject: [PATCH 2/4] feat: serialise in `toJSON()` --- packages/discord.js/src/structures/GuildMember.js | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/discord.js/src/structures/GuildMember.js b/packages/discord.js/src/structures/GuildMember.js index b9dc7935e6ce..34d219605e9f 100644 --- a/packages/discord.js/src/structures/GuildMember.js +++ b/packages/discord.js/src/structures/GuildMember.js @@ -523,6 +523,7 @@ class GuildMember extends Base { }); json.avatarURL = this.avatarURL(); json.displayAvatarURL = this.displayAvatarURL(); + json.displayBannerURL = this.displayBannerURL(); return json; } } From 61134c4d4826eaa1d900e77428c59fb9ff7acaf8 Mon Sep 17 00:00:00 2001 From: Jiralite <33201955+Jiralite@users.noreply.github.com> Date: Fri, 12 Jul 2024 10:55:18 +0100 Subject: [PATCH 3/4] feat: serialise in `toJSON()` --- packages/discord.js/src/structures/GuildMember.js | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/discord.js/src/structures/GuildMember.js b/packages/discord.js/src/structures/GuildMember.js index 34d219605e9f..e7ac593aed0a 100644 --- a/packages/discord.js/src/structures/GuildMember.js +++ b/packages/discord.js/src/structures/GuildMember.js @@ -522,6 +522,7 @@ class GuildMember extends Base { roles: true, }); json.avatarURL = this.avatarURL(); + json.bannerURL = this.bannerURL(); json.displayAvatarURL = this.displayAvatarURL(); json.displayBannerURL = this.displayBannerURL(); return json; From 4a8447e1c97f894a51fd350d51aeef28ec9fce5b Mon Sep 17 00:00:00 2001 From: Jiralite <33201955+Jiralite@users.noreply.github.com> Date: Fri, 12 Jul 2024 10:57:19 +0100 Subject: [PATCH 4/4] docs: lowercase i --- packages/discord.js/src/structures/GuildMember.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/discord.js/src/structures/GuildMember.js b/packages/discord.js/src/structures/GuildMember.js index e7ac593aed0a..ae7b4753ccad 100644 --- a/packages/discord.js/src/structures/GuildMember.js +++ b/packages/discord.js/src/structures/GuildMember.js @@ -188,7 +188,7 @@ class GuildMember extends Base { /** * A link to the member's guild banner if they have one. * Otherwise, a link to their {@link User#bannerURL} will be returned. - * @param {ImageURLOptions} [options={}] Options for the Image URL + * @param {ImageURLOptions} [options={}] Options for the image URL * @returns {?string} */ displayBannerURL(options) {