diff --git a/packages/discord.js/src/structures/User.js b/packages/discord.js/src/structures/User.js index 33f8e66838fd..4e38d2da4d42 100644 --- a/packages/discord.js/src/structures/User.js +++ b/packages/discord.js/src/structures/User.js @@ -122,6 +122,16 @@ class User extends Base { */ this.flags = new UserFlagsBitField(data.public_flags); } + + if ('avatar_decoration' in data) { + /** + * The user avatar decoration's hash + * @type {?string} + */ + this.avatarDecoration = data.avatar_decoration; + } else { + this.avatarDecoration ??= null; + } } /** @@ -160,6 +170,15 @@ class User extends Base { return this.avatar && this.client.rest.cdn.avatar(this.id, this.avatar, options); } + /** + * A link to the user's avatar decoration. + * @param {BaseImageURLOptions} [options={}] Options for the image URL + * @returns {?string} + */ + avatarDecorationURL(options = {}) { + return this.avatarDecoration && this.client.rest.cdn.avatarDecoration(this.id, this.avatarDecoration, options); + } + /** * A link to the user's default avatar * @type {string} diff --git a/packages/discord.js/typings/index.d.ts b/packages/discord.js/typings/index.d.ts index 38faf58b70f5..db190f079024 100644 --- a/packages/discord.js/typings/index.d.ts +++ b/packages/discord.js/typings/index.d.ts @@ -3096,6 +3096,7 @@ export class User extends PartialTextBasedChannel(Base) { public accentColor: number | null | undefined; public avatar: string | null; + public avatarDecoration: string | null; public banner: string | null | undefined; public bot: boolean; public get createdAt(): Date; @@ -3113,6 +3114,7 @@ export class User extends PartialTextBasedChannel(Base) { public get tag(): string; public username: string; public avatarURL(options?: ImageURLOptions): string | null; + public avatarDecorationURL(options?: BaseImageURLOptions): string | null; public bannerURL(options?: ImageURLOptions): string | null | undefined; public createDM(force?: boolean): Promise; public deleteDM(): Promise; diff --git a/packages/rest/src/lib/CDN.ts b/packages/rest/src/lib/CDN.ts index a42966bd8829..6f40e7486db7 100644 --- a/packages/rest/src/lib/CDN.ts +++ b/packages/rest/src/lib/CDN.ts @@ -96,6 +96,21 @@ export class CDN { return this.dynamicMakeURL(`/avatars/${id}/${avatarHash}`, avatarHash, options); } + /** + * Generates a user avatar decoration URL. + * + * @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 + */ + public avatarDecoration( + userId: string, + userAvatarDecoration: string, + options?: Readonly, + ): string { + return this.makeURL(`/avatar-decorations/${userId}/${userAvatarDecoration}`, options); + } + /** * Generates a banner URL, e.g. for a user or a guild. *