Skip to content

Commit

Permalink
feat(GuildMember): add member banner
Browse files Browse the repository at this point in the history
  • Loading branch information
Koyamie committed Aug 22, 2024
1 parent 28bc364 commit 0ae7d13
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
22 changes: 22 additions & 0 deletions packages/discord.js/src/structures/GuildMember.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,16 @@ class GuildMember extends Base {
} else if (typeof this.avatar !== 'string') {
this.avatar = null;
}
if ('banner' in data) {
/**
* The guild member's banner hash
* <info>The user must be force fetched for this property to be present or be updated</info>
* @type {?string}
*/
this.banner = data.banner;
} else if (this.banner !== null) {
this.banner ??= undefined;
}
if ('joined_at' in data) this.joinedTimestamp = new Date(data.joined_at).getTime();
if ('premium_since' in data) {
this.premiumSinceTimestamp = data.premium_since ? new Date(data.premium_since).getTime() : null;
Expand Down Expand Up @@ -195,6 +205,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.
* @param {ImageURLOptions} [options={}] Options for the Image URL
* @returns {?string}
*/
bannerURL({ format, size, dynamic } = {}) {
if (!this.banner) return this.banner;
return this.client.rest.cdn.Banner(this.id, this.banner, format, size, dynamic);
}

/**
* The time this member joined the guild
* @type {?Date}
Expand Down Expand Up @@ -484,6 +504,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.equals(member.flags) &&
Expand Down Expand Up @@ -512,6 +533,7 @@ class GuildMember extends Base {
});
json.avatarURL = this.avatarURL();
json.displayAvatarURL = this.displayAvatarURL();
json.bannerURL = this.banner ? this.bannerURL() : this.banner;
return json;
}
}
Expand Down
1 change: 1 addition & 0 deletions packages/discord.js/typings/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1240,6 +1240,7 @@ export class GuildMember extends PartialTextBasedChannel(Base) {
public createDM(force?: boolean): Promise<DMChannel>;
public deleteDM(): Promise<DMChannel>;
public displayAvatarURL(options?: ImageURLOptions): string;
public bannerURL(options?: ImageURLOptions): string | null;
public edit(data: GuildMemberEditData, reason?: string): Promise<GuildMember>;
public isCommunicationDisabled(): this is GuildMember & {
communicationDisabledUntilTimestamp: number;
Expand Down

0 comments on commit 0ae7d13

Please sign in to comment.