From b1ded63e42e7349f535df4680509b9393dd8f288 Mon Sep 17 00:00:00 2001 From: Jiralite <33201955+Jiralite@users.noreply.github.com> Date: Mon, 4 Nov 2024 10:43:34 +0000 Subject: [PATCH] feat(GuildMember): Banners (#10384) * feat: initial support for guild member banners * feat: serialise in `toJSON()` * feat: serialise in `toJSON()` * docs: lowercase i --------- Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com> --- .../discord.js/src/structures/GuildMember.js | 33 +++++++++++++++++++ packages/discord.js/typings/index.d.ts | 3 ++ 2 files changed, 36 insertions(+) diff --git a/packages/discord.js/src/structures/GuildMember.js b/packages/discord.js/src/structures/GuildMember.js index db71c66b5473..b03a1bc4d6ec 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 && @@ -491,7 +522,9 @@ class GuildMember extends Base { roles: true, }); json.avatarURL = this.avatarURL(); + json.bannerURL = this.bannerURL(); json.displayAvatarURL = this.displayAvatarURL(); + json.displayBannerURL = this.displayBannerURL(); return json; } } diff --git a/packages/discord.js/typings/index.d.ts b/packages/discord.js/typings/index.d.ts index e9982abc2013..8927f59bbdd6 100644 --- a/packages/discord.js/typings/index.d.ts +++ b/packages/discord.js/typings/index.d.ts @@ -1658,6 +1658,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; @@ -1684,6 +1685,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; @@ -1691,6 +1693,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;