From b1bfe94b7deba3216dc25903e27a412e25354821 Mon Sep 17 00:00:00 2001 From: Fleny Date: Mon, 2 Sep 2024 15:12:09 +0200 Subject: [PATCH] Use atob instead of node:buffer for getBotIdFromToken (#3893) --- packages/rest/tests/constants.ts | 2 +- packages/utils/src/token.ts | 4 +--- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/packages/rest/tests/constants.ts b/packages/rest/tests/constants.ts index c4c45cb13..9420cf0e9 100644 --- a/packages/rest/tests/constants.ts +++ b/packages/rest/tests/constants.ts @@ -1,3 +1,3 @@ import { Buffer } from 'node:buffer' -export const fakeToken = `${Buffer.from('1033452747380494366', 'base64').toString()}.zawsxedcrftvgybhu` +export const fakeToken = `${Buffer.from('1033452747380494366').toString('base64')}.zawsxedcrftvgybhu` diff --git a/packages/utils/src/token.ts b/packages/utils/src/token.ts index abcd6e92f..79bf2e58a 100644 --- a/packages/utils/src/token.ts +++ b/packages/utils/src/token.ts @@ -1,5 +1,3 @@ -import { Buffer } from 'node:buffer' - const validTokenPrefixes = ['Bot', 'Bearer'] /** Removes the Bot/Bearer before the token. */ @@ -19,5 +17,5 @@ export function removeTokenPrefix(token?: string, type: 'GATEWAY' | 'REST' = 'RE /** Get the bot id from the bot token. WARNING: Discord staff has mentioned this may not be stable forever. Use at your own risk. However, note for over 5 years this has never broken. */ export function getBotIdFromToken(token: string): bigint { - return BigInt(Buffer.from(token.split('.')[0], 'base64').toString()) + return BigInt(atob(token.split('.')[0])) }