File tree Expand file tree Collapse file tree 3 files changed +23
-8
lines changed
Expand file tree Collapse file tree 3 files changed +23
-8
lines changed Original file line number Diff line number Diff line change @@ -214,13 +214,7 @@ class Client extends BaseClient {
214214 if ( ! token || typeof token !== 'string' ) throw new DiscordjsError ( ErrorCodes . TokenInvalid ) ;
215215 this . token = token = token . replace ( / ^ ( B o t | B e a r e r ) \s * / i, '' ) ;
216216 this . rest . setToken ( token ) ;
217- this . emit (
218- Events . Debug ,
219- `Provided token: ${ token
220- . split ( '.' )
221- . map ( ( val , i ) => ( i > 1 ? val . replace ( / ./ g, '*' ) : val ) )
222- . join ( '.' ) } `,
223- ) ;
217+ this . emit ( Events . Debug , `Provided token: ${ this . _censoredToken } ` ) ;
224218
225219 if ( this . options . presence ) {
226220 this . options . ws . presence = this . presence . _parse ( this . options . presence ) ;
@@ -459,6 +453,21 @@ class Client extends BaseClient {
459453 } ) ;
460454 }
461455
456+ /**
457+ * Partially censored client token for debug logging purposes.
458+ * @type {?string }
459+ * @readonly
460+ * @private
461+ */
462+ get _censoredToken ( ) {
463+ if ( ! this . token ) return null ;
464+
465+ return this . token
466+ . split ( '.' )
467+ . map ( ( val , i ) => ( i > 1 ? val . replace ( / ./ g, '*' ) : val ) )
468+ . join ( '.' ) ;
469+ }
470+
462471 /**
463472 * Calls {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/eval} on a script
464473 * with the client as `this`.
Original file line number Diff line number Diff line change @@ -740,7 +740,12 @@ class WebSocketShard extends EventEmitter {
740740 */
741741 _send ( data ) {
742742 if ( this . connection ?. readyState !== WebSocket . OPEN ) {
743- this . debug ( `Tried to send packet '${ JSON . stringify ( data ) } ' but no WebSocket is available!` ) ;
743+ this . debug (
744+ `Tried to send packet '${ JSON . stringify ( data ) . replaceAll (
745+ this . manager . client . token ,
746+ this . manager . client . _censoredToken ,
747+ ) } ' but no WebSocket is available!`,
748+ ) ;
744749 this . destroy ( { closeCode : 4_000 } ) ;
745750 return ;
746751 }
Original file line number Diff line number Diff line change @@ -766,6 +766,7 @@ export class Client<Ready extends boolean = boolean> extends BaseClient {
766766 private presence : ClientPresence ;
767767 private _eval ( script : string ) : unknown ;
768768 private _validateOptions ( options : ClientOptions ) : void ;
769+ private get _censoredToken ( ) : string | null ;
769770
770771 public application : If < Ready , ClientApplication > ;
771772 public channels : ChannelManager ;
You can’t perform that action at this time.
0 commit comments