Skip to content

Commit 15f7571

Browse files
Jiralitesdanialraza
andcommitted
feat(GuildMember): add avatarDecorationData (#10942)
Co-Authored-By: Danial Raza <[email protected]>
1 parent 3fa429c commit 15f7571

File tree

2 files changed

+41
-1
lines changed

2 files changed

+41
-1
lines changed

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

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,20 @@ class GuildMember extends Base {
122122
} else {
123123
this.flags ??= new GuildMemberFlagsBitField().freeze();
124124
}
125+
126+
if (data.avatar_decoration_data) {
127+
/**
128+
* The member avatar decoration's data
129+
*
130+
* @type {?AvatarDecorationData}
131+
*/
132+
this.avatarDecorationData = {
133+
asset: data.avatar_decoration_data.asset,
134+
skuId: data.avatar_decoration_data.sku_id,
135+
};
136+
} else {
137+
this.avatarDecorationData = null;
138+
}
125139
}
126140

127141
_clone() {
@@ -166,6 +180,15 @@ class GuildMember extends Base {
166180
return this.avatar && this.client.rest.cdn.guildMemberAvatar(this.guild.id, this.id, this.avatar, options);
167181
}
168182

183+
/**
184+
* A link to the member's avatar decoration.
185+
*
186+
* @returns {?string}
187+
*/
188+
avatarDecorationURL() {
189+
return this.avatarDecorationData ? this.client.rest.cdn.avatarDecoration(this.avatarDecorationData.asset) : null;
190+
}
191+
169192
/**
170193
* A link to the member's banner.
171194
* @param {ImageURLOptions} [options={}] Options for the banner URL
@@ -195,6 +218,16 @@ class GuildMember extends Base {
195218
return this.bannerURL(options) ?? this.user.bannerURL(options);
196219
}
197220

221+
/**
222+
* A link to the member's guild avatar decoration if they have one.
223+
* Otherwise, a link to their {@link User#avatarDecorationURL} will be returned.
224+
*
225+
* @returns {?string}
226+
*/
227+
displayAvatarDecorationURL() {
228+
return this.avatarDecorationURL() ?? this.user.avatarDecorationURL();
229+
}
230+
198231
/**
199232
* The time this member joined the guild
200233
* @type {?Date}
@@ -499,7 +532,10 @@ class GuildMember extends Base {
499532
this.communicationDisabledUntilTimestamp === member.communicationDisabledUntilTimestamp &&
500533
this.flags.bitfield === member.flags.bitfield &&
501534
(this._roles === member._roles ||
502-
(this._roles.length === member._roles.length && this._roles.every((role, i) => role === member._roles[i])))
535+
(this._roles.length === member._roles.length &&
536+
this._roles.every((role, index) => role === member._roles[index]))) &&
537+
this.avatarDecorationData?.asset === member.avatarDecorationData?.asset &&
538+
this.avatarDecorationData?.skuId === member.avatarDecorationData?.skuId
503539
);
504540
}
505541

@@ -525,6 +561,7 @@ class GuildMember extends Base {
525561
json.bannerURL = this.bannerURL();
526562
json.displayAvatarURL = this.displayAvatarURL();
527563
json.displayBannerURL = this.displayBannerURL();
564+
json.avatarDecorationURL = this.avatarDecorationURL();
528565
return json;
529566
}
530567
}

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1799,6 +1799,7 @@ export class GuildMember extends Base {
17991799
private constructor(client: Client<true>, data: RawGuildMemberData, guild: Guild);
18001800
private _roles: Snowflake[];
18011801
public avatar: string | null;
1802+
public avatarDecorationData: AvatarDecorationData | null;
18021803
public banner: string | null;
18031804
public get bannable(): boolean;
18041805
public get dmChannel(): DMChannel | null;
@@ -1826,6 +1827,7 @@ export class GuildMember extends Base {
18261827
public user: User;
18271828
public get voice(): VoiceState;
18281829
public avatarURL(options?: ImageURLOptions): string | null;
1830+
public avatarDecorationURL(): string | null;
18291831
public bannerURL(options?: ImageURLOptions): string | null;
18301832
public ban(options?: BanOptions): Promise<GuildMember>;
18311833
public disableCommunicationUntil(timeout: DateResolvable | null, reason?: string): Promise<GuildMember>;
@@ -1835,6 +1837,7 @@ export class GuildMember extends Base {
18351837
public deleteDM(): Promise<DMChannel>;
18361838
public displayAvatarURL(options?: ImageURLOptions): string;
18371839
public displayBannerURL(options?: ImageURLOptions): string | null;
1840+
public displayAvatarDecorationURL(): string | null;
18381841
public edit(options: GuildMemberEditOptions): Promise<GuildMember>;
18391842
public isCommunicationDisabled(): this is GuildMember & {
18401843
communicationDisabledUntilTimestamp: number;

0 commit comments

Comments
 (0)