Skip to content

Commit 01c2fbe

Browse files
feat(GuildMember): add avatarDecorationData (#10942)
* feat(GuildMember): add `avatarDecorationData` * feat: add `displayAvatarDecoration()` * docs: missing `@returns` --------- Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
1 parent 8e374aa commit 01c2fbe

File tree

2 files changed

+41
-2
lines changed

2 files changed

+41
-2
lines changed

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

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,20 @@ class GuildMember extends Base {
133133
} else {
134134
this.flags ??= new GuildMemberFlagsBitField().freeze();
135135
}
136+
137+
if (data.avatar_decoration_data) {
138+
/**
139+
* The member avatar decoration's data
140+
*
141+
* @type {?AvatarDecorationData}
142+
*/
143+
this.avatarDecorationData = {
144+
asset: data.avatar_decoration_data.asset,
145+
skuId: data.avatar_decoration_data.sku_id,
146+
};
147+
} else {
148+
this.avatarDecorationData = null;
149+
}
136150
}
137151

138152
_clone() {
@@ -181,6 +195,15 @@ class GuildMember extends Base {
181195
return this.avatar && this.client.rest.cdn.guildMemberAvatar(this.guild.id, this.id, this.avatar, options);
182196
}
183197

198+
/**
199+
* A link to the member's avatar decoration.
200+
*
201+
* @returns {?string}
202+
*/
203+
avatarDecorationURL() {
204+
return this.avatarDecorationData ? this.client.rest.cdn.avatarDecoration(this.avatarDecorationData.asset) : null;
205+
}
206+
184207
/**
185208
* A link to the member's banner.
186209
*
@@ -213,6 +236,16 @@ class GuildMember extends Base {
213236
return this.bannerURL(options) ?? this.user.bannerURL(options);
214237
}
215238

239+
/**
240+
* A link to the member's guild avatar decoration if they have one.
241+
* Otherwise, a link to their {@link User#avatarDecorationURL} will be returned.
242+
*
243+
* @returns {?string}
244+
*/
245+
displayAvatarDecorationURL() {
246+
return this.avatarDecorationURL() ?? this.user.avatarDecorationURL();
247+
}
248+
216249
/**
217250
* The time this member joined the guild
218251
*
@@ -560,7 +593,9 @@ class GuildMember extends Base {
560593
this.flags.bitfield === member.flags.bitfield &&
561594
(this._roles === member._roles ||
562595
(this._roles.length === member._roles.length &&
563-
this._roles.every((role, index) => role === member._roles[index])))
596+
this._roles.every((role, index) => role === member._roles[index]))) &&
597+
this.avatarDecorationData?.asset === member.avatarDecorationData?.asset &&
598+
this.avatarDecorationData?.skuId === member.avatarDecorationData?.skuId
564599
);
565600
}
566601

@@ -587,6 +622,7 @@ class GuildMember extends Base {
587622
json.bannerURL = this.bannerURL();
588623
json.displayAvatarURL = this.displayAvatarURL();
589624
json.displayBannerURL = this.displayBannerURL();
625+
json.avatarDecorationURL = this.avatarDecorationURL();
590626
return json;
591627
}
592628
}

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1596,6 +1596,7 @@ export class GuildMember extends Base {
15961596
private constructor(client: Client<true>, data: unknown, guild: Guild);
15971597
private readonly _roles: Snowflake[];
15981598
public avatar: string | null;
1599+
public avatarDecorationData: AvatarDecorationData | null;
15991600
public banner: string | null;
16001601
public get bannable(): boolean;
16011602
public get dmChannel(): DMChannel | null;
@@ -1623,6 +1624,7 @@ export class GuildMember extends Base {
16231624
public user: User;
16241625
public get voice(): VoiceState;
16251626
public avatarURL(options?: ImageURLOptions): string | null;
1627+
public avatarDecorationURL(): string | null;
16261628
public bannerURL(options?: ImageURLOptions): string | null;
16271629
public ban(options?: BanOptions): Promise<void>;
16281630
public disableCommunicationUntil(timeout: DateResolvable | null, reason?: string): Promise<GuildMember>;
@@ -1632,6 +1634,7 @@ export class GuildMember extends Base {
16321634
public deleteDM(): Promise<DMChannel>;
16331635
public displayAvatarURL(options?: ImageURLOptions): string;
16341636
public displayBannerURL(options?: ImageURLOptions): string | null;
1637+
public displayAvatarDecorationURL(): string | null;
16351638
public edit(options: GuildMemberEditOptions): Promise<GuildMember>;
16361639
public isCommunicationDisabled(): this is GuildMember & {
16371640
readonly communicationDisabledUntil: Date;
@@ -3534,7 +3537,7 @@ export class User extends Base {
35343537
public get tag(): string;
35353538
public username: string;
35363539
public avatarURL(options?: ImageURLOptions): string | null;
3537-
public avatarDecorationURL(options?: BaseImageURLOptions): string | null;
3540+
public avatarDecorationURL(): string | null;
35383541
public bannerURL(options?: ImageURLOptions): string | null | undefined;
35393542
public createDM(force?: boolean): Promise<DMChannel>;
35403543
public deleteDM(): Promise<DMChannel>;

0 commit comments

Comments
 (0)