diff --git a/packages/discord.js/src/structures/User.js b/packages/discord.js/src/structures/User.js index 4e38d2da4d421..d325af624cdda 100644 --- a/packages/discord.js/src/structures/User.js +++ b/packages/discord.js/src/structures/User.js @@ -127,11 +127,31 @@ class User extends Base { /** * The user avatar decoration's hash * @type {?string} + * @deprecated Use `avatarDecorationData` instead */ this.avatarDecoration = data.avatar_decoration; } else { this.avatarDecoration ??= null; } + + /** + * @typedef {Object} AvatarDecorationData + * @property {string} asset The avatar decoration hash + * @property {Snowflake} skuId The id of the avatar decoration's SKU + */ + + if (data.avatar_decoration_data) { + /** + * The user avatar decoration's data + * @type {?AvatarDecorationData} + */ + this.avatarDecorationData = { + asset: data.avatar_decoration_data.asset, + skuId: data.avatar_decoration_data.sku_id, + }; + } else { + this.avatarDecorationData = null; + } } /** @@ -176,6 +196,10 @@ class User extends Base { * @returns {?string} */ avatarDecorationURL(options = {}) { + if (this.avatarDecorationData) { + return this.client.rest.cdn.avatarDecoration(this.avatarDecorationData.asset, options); + } + return this.avatarDecoration && this.client.rest.cdn.avatarDecoration(this.id, this.avatarDecoration, options); } diff --git a/packages/discord.js/typings/index.d.ts b/packages/discord.js/typings/index.d.ts index 1a80284102b0f..1f4954a5293f6 100644 --- a/packages/discord.js/typings/index.d.ts +++ b/packages/discord.js/typings/index.d.ts @@ -3131,13 +3131,20 @@ export class Typing extends Base { }; } +export interface AvatarDecorationData { + asset: string; + skuId: Snowflake; +} + export class User extends PartialTextBasedChannel(Base) { protected constructor(client: Client, data: RawUserData); private _equals(user: APIUser): boolean; public accentColor: number | null | undefined; public avatar: string | null; + /** @deprecated Use {@link avatarDecorationData} instead */ public avatarDecoration: string | null; + public avatarDecorationData: AvatarDecorationData | null; public banner: string | null | undefined; public bot: boolean; public get createdAt(): Date; diff --git a/packages/rest/src/lib/CDN.ts b/packages/rest/src/lib/CDN.ts index 6ef6f67e2b27a..749e8f4da68da 100644 --- a/packages/rest/src/lib/CDN.ts +++ b/packages/rest/src/lib/CDN.ts @@ -97,9 +97,18 @@ export class CDN { return this.dynamicMakeURL(`/avatars/${id}/${avatarHash}`, avatarHash, options); } + /** + * Generates a user avatar decoration preset URL. + * + * @param asset - The avatar decoration hash + * @param options - Optional options for the avatar decoration preset + */ + public avatarDecoration(asset: string, options?: Readonly): string; + /** * Generates a user avatar decoration URL. * + * @deprecated This overload is deprecated. Pass an hash instead. * @param userId - The id of the user * @param userAvatarDecoration - The hash provided by Discord for this avatar decoration * @param options - Optional options for the avatar decoration @@ -108,8 +117,18 @@ export class CDN { userId: string, userAvatarDecoration: string, options?: Readonly, + ): string; + + public avatarDecoration( + userIdOrAsset: string, + assetOrOptions?: Readonly | string, + options?: Readonly, ): string { - return this.makeURL(`/avatar-decorations/${userId}/${userAvatarDecoration}`, options); + if (typeof assetOrOptions === 'string') { + return this.makeURL(`/avatar-decorations/${userIdOrAsset}/${assetOrOptions}`, options); + } + + return this.makeURL(`/avatar-decoration-presets/${userIdOrAsset}`, assetOrOptions); } /**