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 <github@almeidx.dev>

---------

Co-authored-by: Almeida <github@almeidx.dev>
This commit is contained in:
Denis Cristea
2024-10-09 13:49:27 +03:00
committed by GitHub
parent c8ef899a68
commit c36728a814

View File

@@ -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...');