Skip to content

Commit

Permalink
fix(Client): never pass token in ws constructor (#10544)
Browse files Browse the repository at this point in the history
* fix(Client): never pass token in ws constructor

* chore: don't reassign parameter

Co-authored-by: Almeida <[email protected]>

---------

Co-authored-by: Almeida <[email protected]>
  • Loading branch information
didinele and almeidx authored Oct 9, 2024
1 parent c8ef899 commit c36728a
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions packages/discord.js/src/client/Client.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};

/**
Expand Down Expand Up @@ -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...');

Expand Down

0 comments on commit c36728a

Please sign in to comment.