fix: use calculateUserDefaultAvatarIndex function

This commit is contained in:
MARCROCK22 2024-04-14 12:14:54 -04:00
parent 0392de7964
commit 28133b2c1f
2 changed files with 4 additions and 5 deletions

View File

@ -5,8 +5,8 @@ import type { Snowflake } from 'discord-api-types/v10';
* *
* @param userId - The user id to calculate the default avatar index for * @param userId - The user id to calculate the default avatar index for
*/ */
export function calculateUserDefaultAvatarIndex(userId: Snowflake) { export function calculateUserDefaultAvatarIndex(userId: Snowflake, discriminator: string) {
return Number(BigInt(userId) >> 22n) % 6; return discriminator === '0' ? Number(BigInt(userId) >> 22n) % 6 : Number.parseInt(discriminator) % 5;
} }
/** /**

View File

@ -1,4 +1,5 @@
import type { APIUser } from 'discord-api-types/v10'; import type { APIUser } from 'discord-api-types/v10';
import { calculateUserDefaultAvatarIndex } from '../api';
import type { MessageCreateBodyRequest, ObjectToLower } from '../common'; import type { MessageCreateBodyRequest, ObjectToLower } from '../common';
import type { ImageOptions } from '../common/types/options'; import type { ImageOptions } from '../common/types/options';
import { DiscordBase } from './extra/DiscordBase'; import { DiscordBase } from './extra/DiscordBase';
@ -34,9 +35,7 @@ export class User extends DiscordBase<APIUser> {
avatarURL(options?: ImageOptions) { avatarURL(options?: ImageOptions) {
if (!this.avatar) { if (!this.avatar) {
const avatarIndex = return this.rest.cdn.embed.avatars.get(calculateUserDefaultAvatarIndex(this.id, this.discriminator));
this.discriminator === '0' ? Number(BigInt(this.id) >> 22n) % 6 : Number.parseInt(this.discriminator) % 5;
return this.rest.cdn.embed.avatars.get(avatarIndex);
} }
return this.rest.cdn.avatars(this.id).get(this.avatar, options); return this.rest.cdn.avatars(this.id).get(this.avatar, options);
} }