mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-17 20:13:30 +01:00
feat: user avatar decorations (#8914)
feat(User): add avatar decorations Co-authored-by: Jiralite <33201955+Jiralite@users.noreply.github.com>
This commit is contained in:
@@ -122,6 +122,16 @@ class User extends Base {
|
|||||||
*/
|
*/
|
||||||
this.flags = new UserFlagsBitField(data.public_flags);
|
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);
|
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
|
* A link to the user's default avatar
|
||||||
* @type {string}
|
* @type {string}
|
||||||
|
|||||||
2
packages/discord.js/typings/index.d.ts
vendored
2
packages/discord.js/typings/index.d.ts
vendored
@@ -3096,6 +3096,7 @@ export class User extends PartialTextBasedChannel(Base) {
|
|||||||
|
|
||||||
public accentColor: number | null | undefined;
|
public accentColor: number | null | undefined;
|
||||||
public avatar: string | null;
|
public avatar: string | null;
|
||||||
|
public avatarDecoration: string | null;
|
||||||
public banner: string | null | undefined;
|
public banner: string | null | undefined;
|
||||||
public bot: boolean;
|
public bot: boolean;
|
||||||
public get createdAt(): Date;
|
public get createdAt(): Date;
|
||||||
@@ -3113,6 +3114,7 @@ export class User extends PartialTextBasedChannel(Base) {
|
|||||||
public get tag(): string;
|
public get tag(): string;
|
||||||
public username: string;
|
public username: string;
|
||||||
public avatarURL(options?: ImageURLOptions): string | null;
|
public avatarURL(options?: ImageURLOptions): string | null;
|
||||||
|
public avatarDecorationURL(options?: BaseImageURLOptions): string | null;
|
||||||
public bannerURL(options?: ImageURLOptions): string | null | undefined;
|
public bannerURL(options?: ImageURLOptions): string | null | undefined;
|
||||||
public createDM(force?: boolean): Promise<DMChannel>;
|
public createDM(force?: boolean): Promise<DMChannel>;
|
||||||
public deleteDM(): Promise<DMChannel>;
|
public deleteDM(): Promise<DMChannel>;
|
||||||
|
|||||||
@@ -96,6 +96,21 @@ export class CDN {
|
|||||||
return this.dynamicMakeURL(`/avatars/${id}/${avatarHash}`, avatarHash, options);
|
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<BaseImageURLOptions>,
|
||||||
|
): string {
|
||||||
|
return this.makeURL(`/avatar-decorations/${userId}/${userAvatarDecoration}`, options);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Generates a banner URL, e.g. for a user or a guild.
|
* Generates a banner URL, e.g. for a user or a guild.
|
||||||
*
|
*
|
||||||
|
|||||||
Reference in New Issue
Block a user