mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-11 09:03:29 +01:00
feat(User): banners and accent colors (#6117)
* feat(User): support banners don't mind it for now, just trying * feat(User): support banners * fix(Constants): declare dynamic * fix(User): eslint * typings: update User typings * fix(User): add banner to equals and json bannerURL * typings: missing dynamic * refactor: xID to xId * types: re-add typings * feat: add banner color and fetch note * feat: switch to accent color (swap hex and dec)) * Update src/structures/User.js Co-authored-by: Rodry <38259440+ImRodry@users.noreply.github.com> * Update typings/index.d.ts Co-authored-by: Rodry <38259440+ImRodry@users.noreply.github.com> * Apply suggestions from code review Co-authored-by: Koyamie <koyamie1@gmail.com> Co-authored-by: Noel <icrawltogo@gmail.com> Co-authored-by: Rodry <38259440+ImRodry@users.noreply.github.com>
This commit is contained in:
@@ -75,6 +75,28 @@ class User extends Base {
|
||||
this.avatar = null;
|
||||
}
|
||||
|
||||
if ('banner' in data) {
|
||||
/**
|
||||
* The user banner's hash
|
||||
* <info>The user must be force fetched for this property to be present</info>
|
||||
* @type {?string}
|
||||
*/
|
||||
this.banner = data.banner;
|
||||
} else if (typeof this.banner !== 'string') {
|
||||
this.banner = null;
|
||||
}
|
||||
|
||||
if ('accent_color' in data) {
|
||||
/**
|
||||
* The base 10 accent color of the user's banner
|
||||
* <info>The user must be force fetched for this property to be present</info>
|
||||
* @type {?number}
|
||||
*/
|
||||
this.accentColor = data.accent_color;
|
||||
} else if (typeof this.accentColor === 'undefined') {
|
||||
this.accentColor = null;
|
||||
}
|
||||
|
||||
if ('system' in data) {
|
||||
/**
|
||||
* Whether the user is an Official Discord System user (part of the urgent message system)
|
||||
@@ -150,6 +172,28 @@ class User extends Base {
|
||||
return this.avatarURL(options) ?? this.defaultAvatarURL;
|
||||
}
|
||||
|
||||
/**
|
||||
* The hexadecimal version of the user accent color, with a leading hash
|
||||
* <info>The user must be force fetched for this property to be present</info>
|
||||
* @type {?string}
|
||||
* @readonly
|
||||
*/
|
||||
get hexAccentColor() {
|
||||
if (!this.accentColor) return null;
|
||||
return `#${this.accentColor.toString(16).padStart(6, '0')}`;
|
||||
}
|
||||
|
||||
/**
|
||||
* A link to the user's banner.
|
||||
* <info>The user must be force fetched for this property to be present</info>
|
||||
* @param {ImageURLOptions} [options={}] Options for the Image URL
|
||||
* @returns {?string}
|
||||
*/
|
||||
bannerURL({ format, size, dynamic } = {}) {
|
||||
if (!this.banner) return null;
|
||||
return this.client.rest.cdn.Banner(this.id, this.banner, format, size, dynamic);
|
||||
}
|
||||
|
||||
/**
|
||||
* The Discord "tag" (e.g. `hydrabolt#0001`) for this user
|
||||
* @type {?string}
|
||||
@@ -200,7 +244,8 @@ class User extends Base {
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the user is equal to another. It compares id, username, discriminator, avatar, and bot flags.
|
||||
* Checks if the user is equal to another.
|
||||
* It compares id, username, discriminator, avatar, banner, accent color, and bot flags.
|
||||
* It is recommended to compare equality by using `user.id === user2.id` unless you want to compare all properties.
|
||||
* @param {User} user User to compare with
|
||||
* @returns {boolean}
|
||||
@@ -211,7 +256,9 @@ class User extends Base {
|
||||
this.id === user.id &&
|
||||
this.username === user.username &&
|
||||
this.discriminator === user.discriminator &&
|
||||
this.avatar === user.avatar;
|
||||
this.avatar === user.avatar &&
|
||||
this.banner === user.banner &&
|
||||
this.accentColor === user.accentColor;
|
||||
|
||||
return equal;
|
||||
}
|
||||
@@ -253,12 +300,14 @@ class User extends Base {
|
||||
{
|
||||
createdTimestamp: true,
|
||||
defaultAvatarURL: true,
|
||||
hexAccentColor: true,
|
||||
tag: true,
|
||||
},
|
||||
...props,
|
||||
);
|
||||
json.avatarURL = this.avatarURL();
|
||||
json.displayAvatarURL = this.displayAvatarURL();
|
||||
json.bannerURL = this.bannerURL();
|
||||
return json;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user