From c36728a8144a7522da950b6436d33aa305281a73 Mon Sep 17 00:00:00 2001 From: Denis Cristea Date: Wed, 9 Oct 2024 13:49:27 +0300 Subject: [PATCH] fix(Client): never pass token in ws constructor (#10544) * fix(Client): never pass token in ws constructor * chore: don't reassign parameter Co-authored-by: Almeida --------- Co-authored-by: Almeida --- packages/discord.js/src/client/Client.js | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/packages/discord.js/src/client/Client.js b/packages/discord.js/src/client/Client.js index 048cfb32d..7d528b37c 100644 --- a/packages/discord.js/src/client/Client.js +++ b/packages/discord.js/src/client/Client.js @@ -160,7 +160,8 @@ class Client extends BaseClient { ...this.options.ws, intents: this.options.intents.bitfield, rest: this.rest, - token: this.token, + // Explicitly nulled to always be set using `setToken` in `login` + token: null, }; /** @@ -257,8 +258,10 @@ class Client extends BaseClient { */ async login(token = this.token) { if (!token || typeof token !== 'string') throw new DiscordjsError(ErrorCodes.TokenInvalid); - this.token = token = token.replace(/^(Bot|Bearer)\s*/i, ''); - this.rest.setToken(token); + this.token = token.replace(/^(Bot|Bearer)\s*/i, ''); + + this.rest.setToken(this.token); + this.emit(Events.Debug, `Provided token: ${this._censoredToken}`); this.emit(Events.Debug, 'Preparing to connect to the gateway...');