mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-12 01:23:31 +01:00
feat: support new username system (#9512)
* feat: support new username system * docs(GuildMember#displayName): update * fix(User#hasNewUsername): use User#discriminator * feat(User#tag): add new username * docs(User#tag): update * docs(User#hasNewUsername): update * docs: update * feat(User#defaultAvatarURL): update * feat: remove some newly added properties * docs(User#discriminator): update * docs(User#globalName): bad Copilot * feat(User#displayName): return display name * types(User#displayName): not a partial structure * feat: add `calculateUserDefaultAvatarId` function * docs(CND#defaultAvatar): update * docs(CDN#defaultAvatar): update * feat: change default avatar id to type * feat: deprecate `User#tag` * docs(CDN#defaultAvatar): update Co-authored-by: Jiralite <33201955+Jiralite@users.noreply.github.com> * docs(User): update Co-authored-by: Rodrigo Leitão <38259440+ImRodry@users.noreply.github.com> * feat: update * typing: update Co-authored-by: Jan <66554238+vaporoxx@users.noreply.github.com> * feat: change the param type to `Snowflake` --------- Co-authored-by: Jiralite <33201955+Jiralite@users.noreply.github.com> Co-authored-by: Rodrigo Leitão <38259440+ImRodry@users.noreply.github.com> Co-authored-by: Jan <66554238+vaporoxx@users.noreply.github.com>
This commit is contained in:
@@ -5,7 +5,7 @@ export * from './lib/errors/RateLimitError.js';
|
||||
export * from './lib/RequestManager.js';
|
||||
export * from './lib/REST.js';
|
||||
export * from './lib/utils/constants.js';
|
||||
export { makeURLSearchParams, parseResponse } from './lib/utils/utils.js';
|
||||
export { calculateUserDefaultAvatarIndex, makeURLSearchParams, parseResponse } from './lib/utils/utils.js';
|
||||
|
||||
/**
|
||||
* The {@link https://github.com/discordjs/discord.js/blob/main/packages/rest/#readme | @discordjs/rest} version
|
||||
|
||||
@@ -119,12 +119,15 @@ export class CDN {
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates the default avatar URL for a discriminator.
|
||||
* Generates a default avatar URL
|
||||
*
|
||||
* @param discriminator - The discriminator modulo 5
|
||||
* @param index - The default avatar index
|
||||
* @remarks
|
||||
* To calculate the index for a user do `(userId >> 22) % 6`,
|
||||
* or `discriminator % 5` if they're using the legacy username system.
|
||||
*/
|
||||
public defaultAvatar(discriminator: number): string {
|
||||
return this.makeURL(`/embed/avatars/${discriminator}`, { extension: 'png' });
|
||||
public defaultAvatar(index: number): string {
|
||||
return this.makeURL(`/embed/avatars/${index}`, { extension: 'png' });
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { URLSearchParams } from 'node:url';
|
||||
import type { RESTPatchAPIChannelJSONBody } from 'discord-api-types/v10';
|
||||
import type { RESTPatchAPIChannelJSONBody, Snowflake } from 'discord-api-types/v10';
|
||||
import type { RateLimitData, ResponseLike } from '../REST.js';
|
||||
import { type RequestManager, RequestMethod } from '../RequestManager.js';
|
||||
import { RateLimitError } from '../errors/RateLimitError.js';
|
||||
@@ -112,3 +112,12 @@ export async function onRateLimit(manager: RequestManager, rateLimitData: RateLi
|
||||
throw new RateLimitError(rateLimitData);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculates the default avatar index for a given user id.
|
||||
*
|
||||
* @param userId - The user id to calculate the default avatar index for
|
||||
*/
|
||||
export function calculateUserDefaultAvatarIndex(userId: Snowflake) {
|
||||
return Number(BigInt(userId) >> 22n) % 6;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user