Skip to content

Commit ef2a687

Browse files
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>
1 parent a9f629b commit ef2a687

File tree

2 files changed

+36
-0
lines changed

2 files changed

+36
-0
lines changed

packages/discord.js/src/structures/GuildMember.js

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,17 @@ class GuildMember extends Base {
8484
} else if (typeof this.avatar !== 'string') {
8585
this.avatar = null;
8686
}
87+
88+
if ('banner' in data) {
89+
/**
90+
* The guild member's banner hash.
91+
* @type {?string}
92+
*/
93+
this.banner = data.banner;
94+
} else {
95+
this.banner ??= null;
96+
}
97+
8798
if ('joined_at' in data) this.joinedTimestamp = Date.parse(data.joined_at);
8899
if ('premium_since' in data) {
89100
this.premiumSinceTimestamp = data.premium_since ? Date.parse(data.premium_since) : null;
@@ -155,6 +166,15 @@ class GuildMember extends Base {
155166
return this.avatar && this.client.rest.cdn.guildMemberAvatar(this.guild.id, this.id, this.avatar, options);
156167
}
157168

169+
/**
170+
* A link to the member's banner.
171+
* @param {ImageURLOptions} [options={}] Options for the banner URL
172+
* @returns {?string}
173+
*/
174+
bannerURL(options = {}) {
175+
return this.banner && this.client.rest.cdn.guildMemberBanner(this.guild.id, this.id, this.banner, options);
176+
}
177+
158178
/**
159179
* A link to the member's guild avatar if they have one.
160180
* Otherwise, a link to their {@link User#displayAvatarURL} will be returned.
@@ -165,6 +185,16 @@ class GuildMember extends Base {
165185
return this.avatarURL(options) ?? this.user.displayAvatarURL(options);
166186
}
167187

188+
/**
189+
* A link to the member's guild banner if they have one.
190+
* Otherwise, a link to their {@link User#bannerURL} will be returned.
191+
* @param {ImageURLOptions} [options={}] Options for the image URL
192+
* @returns {?string}
193+
*/
194+
displayBannerURL(options) {
195+
return this.bannerURL(options) ?? this.user.bannerURL(options);
196+
}
197+
168198
/**
169199
* The time this member joined the guild
170200
* @type {?Date}
@@ -464,6 +494,7 @@ class GuildMember extends Base {
464494
this.joinedTimestamp === member.joinedTimestamp &&
465495
this.nickname === member.nickname &&
466496
this.avatar === member.avatar &&
497+
this.banner === member.banner &&
467498
this.pending === member.pending &&
468499
this.communicationDisabledUntilTimestamp === member.communicationDisabledUntilTimestamp &&
469500
this.flags.bitfield === member.flags.bitfield &&
@@ -491,7 +522,9 @@ class GuildMember extends Base {
491522
roles: true,
492523
});
493524
json.avatarURL = this.avatarURL();
525+
json.bannerURL = this.bannerURL();
494526
json.displayAvatarURL = this.displayAvatarURL();
527+
json.displayBannerURL = this.displayBannerURL();
495528
return json;
496529
}
497530
}

packages/discord.js/typings/index.d.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1634,6 +1634,7 @@ export class GuildMember extends Base {
16341634
private constructor(client: Client<true>, data: RawGuildMemberData, guild: Guild);
16351635
private _roles: Snowflake[];
16361636
public avatar: string | null;
1637+
public banner: string | null;
16371638
public get bannable(): boolean;
16381639
public get dmChannel(): DMChannel | null;
16391640
public get displayColor(): number;
@@ -1660,13 +1661,15 @@ export class GuildMember extends Base {
16601661
public user: User;
16611662
public get voice(): VoiceState;
16621663
public avatarURL(options?: ImageURLOptions): string | null;
1664+
public bannerURL(options?: ImageURLOptions): string | null;
16631665
public ban(options?: BanOptions): Promise<GuildMember>;
16641666
public disableCommunicationUntil(timeout: DateResolvable | null, reason?: string): Promise<GuildMember>;
16651667
public timeout(timeout: number | null, reason?: string): Promise<GuildMember>;
16661668
public fetch(force?: boolean): Promise<GuildMember>;
16671669
public createDM(force?: boolean): Promise<DMChannel>;
16681670
public deleteDM(): Promise<DMChannel>;
16691671
public displayAvatarURL(options?: ImageURLOptions): string;
1672+
public displayBannerURL(options?: ImageURLOptions): string | null;
16701673
public edit(options: GuildMemberEditOptions): Promise<GuildMember>;
16711674
public isCommunicationDisabled(): this is GuildMember & {
16721675
communicationDisabledUntilTimestamp: number;

0 commit comments

Comments
 (0)