mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-09 16:13:31 +01:00
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>
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
3
packages/discord.js/typings/index.d.ts
vendored
3
packages/discord.js/typings/index.d.ts
vendored
@@ -1634,6 +1634,7 @@ export class GuildMember extends Base {
|
||||
private constructor(client: Client<true>, 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;
|
||||
@@ -1660,6 +1661,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<GuildMember>;
|
||||
public disableCommunicationUntil(timeout: DateResolvable | null, reason?: string): Promise<GuildMember>;
|
||||
public timeout(timeout: number | null, reason?: string): Promise<GuildMember>;
|
||||
@@ -1667,6 +1669,7 @@ export class GuildMember extends Base {
|
||||
public createDM(force?: boolean): Promise<DMChannel>;
|
||||
public deleteDM(): Promise<DMChannel>;
|
||||
public displayAvatarURL(options?: ImageURLOptions): string;
|
||||
public displayBannerURL(options?: ImageURLOptions): string | null;
|
||||
public edit(options: GuildMemberEditOptions): Promise<GuildMember>;
|
||||
public isCommunicationDisabled(): this is GuildMember & {
|
||||
communicationDisabledUntilTimestamp: number;
|
||||
|
||||
Reference in New Issue
Block a user