From 5af7147863d0fcfd9051e2ef6c34fe96e6d6ec40 Mon Sep 17 00:00:00 2001 From: n1ck_pro <59617443+N1ckPro@users.noreply.github.com> Date: Thu, 15 Jun 2023 14:24:48 +0200 Subject: [PATCH] feat: support new username system (#765) --- deno/payloads/v10/user.ts | 6 +++++- deno/payloads/v9/user.ts | 6 +++++- deno/rest/v10/mod.ts | 10 ++++++---- deno/rest/v9/mod.ts | 10 ++++++---- payloads/v10/user.ts | 6 +++++- payloads/v9/user.ts | 6 +++++- rest/v10/index.ts | 10 ++++++---- rest/v9/index.ts | 10 ++++++---- 8 files changed, 44 insertions(+), 20 deletions(-) diff --git a/deno/payloads/v10/user.ts b/deno/payloads/v10/user.ts index 886a00d4..5e72f32a 100644 --- a/deno/payloads/v10/user.ts +++ b/deno/payloads/v10/user.ts @@ -18,9 +18,13 @@ export interface APIUser { */ username: string; /** - * The user's 4-digit discord-tag + * The user's Discord-tag */ discriminator: string; + /** + * The user's display name, if it is set. For bots, this is the application name + */ + global_name: string | null; /** * The user's avatar hash * diff --git a/deno/payloads/v9/user.ts b/deno/payloads/v9/user.ts index 13684d34..20db4bd0 100644 --- a/deno/payloads/v9/user.ts +++ b/deno/payloads/v9/user.ts @@ -18,9 +18,13 @@ export interface APIUser { */ username: string; /** - * The user's 4-digit discord-tag + * The user's Discord-tag */ discriminator: string; + /** + * The user's display name, if it is set. For bots, this is the application name + */ + global_name: string | null; /** * The user's avatar hash * diff --git a/deno/rest/v10/mod.ts b/deno/rest/v10/mod.ts index ee32d725..e024efac 100644 --- a/deno/rest/v10/mod.ts +++ b/deno/rest/v10/mod.ts @@ -962,14 +962,16 @@ export const CDNRoutes = { /** * Route for: - * - GET `/embed/avatars/{user.discriminator % 5}.png` + * - GET `/embed/avatars/{index}.png` * - * The `userDiscriminator` parameter should be the user discriminator modulo 5 (e.g. 1337 % 5 = 2) + * The value for `index` parameter depends on whether the user is [migrated to the new username system](https://discord.com/developers/docs/change-log#unique-usernames-on-discord). + * For users on the new username system, `index` will be `(user.id >> 22) % 6`. + * For users on the legacy username system, `index` will be `user.discriminator % 5`. * * This route supports the extension: PNG */ - defaultUserAvatar(userDiscriminator: DefaultUserAvatarAssets) { - return `/embed/avatars/${userDiscriminator}.png` as const; + defaultUserAvatar(index: DefaultUserAvatarAssets) { + return `/embed/avatars/${index}.png` as const; }, /** diff --git a/deno/rest/v9/mod.ts b/deno/rest/v9/mod.ts index 45943470..8369a400 100644 --- a/deno/rest/v9/mod.ts +++ b/deno/rest/v9/mod.ts @@ -971,14 +971,16 @@ export const CDNRoutes = { /** * Route for: - * - GET `/embed/avatars/{user.discriminator % 5}.png` + * - GET `/embed/avatars/{index}.png` * - * The `userDiscriminator` parameter should be the user discriminator modulo 5 (e.g. 1337 % 5 = 2) + * The value for `index` parameter depends on whether the user is [migrated to the new username system](https://discord.com/developers/docs/change-log#unique-usernames-on-discord). + * For users on the new username system, `index` will be `(user.id >> 22) % 6`. + * For users on the legacy username system, `index` will be `user.discriminator % 5`. * * This route supports the extension: PNG */ - defaultUserAvatar(userDiscriminator: DefaultUserAvatarAssets) { - return `/embed/avatars/${userDiscriminator}.png` as const; + defaultUserAvatar(index: DefaultUserAvatarAssets) { + return `/embed/avatars/${index}.png` as const; }, /** diff --git a/payloads/v10/user.ts b/payloads/v10/user.ts index ec9c478d..75f79a48 100644 --- a/payloads/v10/user.ts +++ b/payloads/v10/user.ts @@ -18,9 +18,13 @@ export interface APIUser { */ username: string; /** - * The user's 4-digit discord-tag + * The user's Discord-tag */ discriminator: string; + /** + * The user's display name, if it is set. For bots, this is the application name + */ + global_name: string | null; /** * The user's avatar hash * diff --git a/payloads/v9/user.ts b/payloads/v9/user.ts index c9f0a21c..45126f37 100644 --- a/payloads/v9/user.ts +++ b/payloads/v9/user.ts @@ -18,9 +18,13 @@ export interface APIUser { */ username: string; /** - * The user's 4-digit discord-tag + * The user's Discord-tag */ discriminator: string; + /** + * The user's display name, if it is set. For bots, this is the application name + */ + global_name: string | null; /** * The user's avatar hash * diff --git a/rest/v10/index.ts b/rest/v10/index.ts index 37e9c8f9..76ccd347 100644 --- a/rest/v10/index.ts +++ b/rest/v10/index.ts @@ -962,14 +962,16 @@ export const CDNRoutes = { /** * Route for: - * - GET `/embed/avatars/{user.discriminator % 5}.png` + * - GET `/embed/avatars/{index}.png` * - * The `userDiscriminator` parameter should be the user discriminator modulo 5 (e.g. 1337 % 5 = 2) + * The value for `index` parameter depends on whether the user is [migrated to the new username system](https://discord.com/developers/docs/change-log#unique-usernames-on-discord). + * For users on the new username system, `index` will be `(user.id >> 22) % 6`. + * For users on the legacy username system, `index` will be `user.discriminator % 5`. * * This route supports the extension: PNG */ - defaultUserAvatar(userDiscriminator: DefaultUserAvatarAssets) { - return `/embed/avatars/${userDiscriminator}.png` as const; + defaultUserAvatar(index: DefaultUserAvatarAssets) { + return `/embed/avatars/${index}.png` as const; }, /** diff --git a/rest/v9/index.ts b/rest/v9/index.ts index 93a7e07d..808d7345 100644 --- a/rest/v9/index.ts +++ b/rest/v9/index.ts @@ -971,14 +971,16 @@ export const CDNRoutes = { /** * Route for: - * - GET `/embed/avatars/{user.discriminator % 5}.png` + * - GET `/embed/avatars/{index}.png` * - * The `userDiscriminator` parameter should be the user discriminator modulo 5 (e.g. 1337 % 5 = 2) + * The value for `index` parameter depends on whether the user is [migrated to the new username system](https://discord.com/developers/docs/change-log#unique-usernames-on-discord). + * For users on the new username system, `index` will be `(user.id >> 22) % 6`. + * For users on the legacy username system, `index` will be `user.discriminator % 5`. * * This route supports the extension: PNG */ - defaultUserAvatar(userDiscriminator: DefaultUserAvatarAssets) { - return `/embed/avatars/${userDiscriminator}.png` as const; + defaultUserAvatar(index: DefaultUserAvatarAssets) { + return `/embed/avatars/${index}.png` as const; }, /**