Skip to content

Commit 90c1fc3

Browse files
committed
feat(User): add avatarDecorationData
1 parent 19ea0ba commit 90c1fc3

File tree

3 files changed

+51
-1
lines changed

3 files changed

+51
-1
lines changed

packages/discord.js/src/structures/User.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,11 +127,31 @@ class User extends Base {
127127
/**
128128
* The user avatar decoration's hash
129129
* @type {?string}
130+
* @deprecated Use `avatarDecorationData` instead
130131
*/
131132
this.avatarDecoration = data.avatar_decoration;
132133
} else {
133134
this.avatarDecoration ??= null;
134135
}
136+
137+
/**
138+
* @typedef {Object} AvatarDecorationData
139+
* @property {string} asset The avatar decoration hash
140+
* @property {Snowflake} skuId The id of the avatar decoration's SKU
141+
*/
142+
143+
if (data.avatar_decoration_data) {
144+
/**
145+
* The user avatar decoration's data
146+
* @type {?AvatarDecorationData}
147+
*/
148+
this.avatarDecorationData = {
149+
asset: data.avatar_decoration_data.asset,
150+
skuId: data.avatar_decoration_data.sku_id,
151+
};
152+
} else {
153+
this.avatarDecorationData = null;
154+
}
135155
}
136156

137157
/**
@@ -176,6 +196,10 @@ class User extends Base {
176196
* @returns {?string}
177197
*/
178198
avatarDecorationURL(options = {}) {
199+
if (this.avatarDecorationData) {
200+
return this.client.rest.cdn.avatarDecoration(this.avatarDecorationData.asset, options);
201+
}
202+
179203
return this.avatarDecoration && this.client.rest.cdn.avatarDecoration(this.id, this.avatarDecoration, options);
180204
}
181205

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3131,13 +3131,20 @@ export class Typing extends Base {
31313131
};
31323132
}
31333133

3134+
export interface AvatarDecorationData {
3135+
asset: string;
3136+
skuId: Snowflake;
3137+
}
3138+
31343139
export class User extends PartialTextBasedChannel(Base) {
31353140
protected constructor(client: Client<true>, data: RawUserData);
31363141
private _equals(user: APIUser): boolean;
31373142

31383143
public accentColor: number | null | undefined;
31393144
public avatar: string | null;
3145+
/** @deprecated Use {@link avatarDecorationData} instead */
31403146
public avatarDecoration: string | null;
3147+
public avatarDecorationData: AvatarDecorationData | null;
31413148
public banner: string | null | undefined;
31423149
public bot: boolean;
31433150
public get createdAt(): Date;

packages/rest/src/lib/CDN.ts

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,9 +97,18 @@ export class CDN {
9797
return this.dynamicMakeURL(`/avatars/${id}/${avatarHash}`, avatarHash, options);
9898
}
9999

100+
/**
101+
* Generates a user avatar decoration preset URL.
102+
*
103+
* @param asset - The avatar decoration hash
104+
* @param options - Optional options for the avatar decoration preset
105+
*/
106+
public avatarDecoration(asset: string, options?: Readonly<BaseImageURLOptions>): string;
107+
100108
/**
101109
* Generates a user avatar decoration URL.
102110
*
111+
* @deprecated This overload is deprecated. Pass an hash instead.
103112
* @param userId - The id of the user
104113
* @param userAvatarDecoration - The hash provided by Discord for this avatar decoration
105114
* @param options - Optional options for the avatar decoration
@@ -108,8 +117,18 @@ export class CDN {
108117
userId: string,
109118
userAvatarDecoration: string,
110119
options?: Readonly<BaseImageURLOptions>,
120+
): string;
121+
122+
public avatarDecoration(
123+
userIdOrAsset: string,
124+
assetOrOptions?: Readonly<BaseImageURLOptions> | string,
125+
options?: Readonly<BaseImageURLOptions>,
111126
): string {
112-
return this.makeURL(`/avatar-decorations/${userId}/${userAvatarDecoration}`, options);
127+
if (typeof assetOrOptions === 'string') {
128+
return this.makeURL(`/avatar-decorations/${userIdOrAsset}/${assetOrOptions}`, options);
129+
}
130+
131+
return this.makeURL(`/avatar-decoration-presets/${userIdOrAsset}`, assetOrOptions);
113132
}
114133

115134
/**

0 commit comments

Comments
 (0)