diff --git a/src/structures/User.js b/src/structures/User.js index e85f0d7..14f9141 100644 --- a/src/structures/User.js +++ b/src/structures/User.js @@ -296,10 +296,24 @@ class User extends Base { if ('badges' in data) { /** - * User badges (Boost, Slash, AutoMod, etc.) - * @type {?Array<{ id: string, description: string, icon: string, link?: string }>} + * @callback BadgeIcon + * @returns {string} */ - this.badges = data.badges; + + /** + * @typedef {Object} UserBadge + * @property {string} id The id of the badge + * @property {string} description The description of the badge + * @property {string} icon The icon hash of the badge + * @property {?string} link The link of the badge + * @property {BadgeIcon} iconURL The iconURL of the badge + */ + + /** + * User badges (Boost, Slash, AutoMod, etc.) + * @type {?Array} + */ + this.badges = data.badges.map(o => ({ ...o, iconURL: () => this.client.rest.cdn.BadgeIcon(o.icon) })); } if ('guild_badges' in data) { diff --git a/src/util/Constants.js b/src/util/Constants.js index e5edc57..652fc28 100644 --- a/src/util/Constants.js +++ b/src/util/Constants.js @@ -227,6 +227,8 @@ exports.Endpoints = { makeImageUrl(`${root}/role-icons/${roleId}/${hash}`, { size, format }), guildScheduledEventCover: (scheduledEventId, coverHash, format, size) => makeImageUrl(`${root}/guild-events/${scheduledEventId}/${coverHash}`, { size, format }), + // Test only + BadgeIcon: hash => makeImageUrl(`${root}/badge-icons/${hash}.png`), }; }, invite: (root, code, eventId) => (eventId ? `${root}/${code}?event=${eventId}` : `${root}/${code}`), diff --git a/typings/index.d.ts b/typings/index.d.ts index 4f70e02..81255cb 100644 --- a/typings/index.d.ts +++ b/typings/index.d.ts @@ -1605,6 +1605,14 @@ export class GuildEmoji extends BaseGuildEmoji { public setName(name: string, reason?: string): Promise; } +export interface UserBadge { + name: string; + description: string; + icon: string; + link?: string; + iconURL(): string; +} + export class GuildMember extends PartialTextBasedChannel(Base) { private constructor(client: Client, data: RawGuildMemberData, guild: Guild); private _roles: Snowflake[]; @@ -1637,7 +1645,7 @@ export class GuildMember extends PartialTextBasedChannel(Base) { public readonly voice: VoiceState; public themeColors?: [number, number]; public readonly hexThemeColor: [string, string] | null; - public badges: { id: string; description: string; icon: string; link?: string }[] | null; + public badges: UserBadge[] | null; public avatarURL(options?: ImageURLOptions): string | null; public ban(options?: BanOptions): Promise; public disableCommunicationUntil(timeout: DateResolvable | null, reason?: string): Promise;