Skip to content

Commit

Permalink
fix(BaseClient): Prevent user agent mutation (#9425)
Browse files Browse the repository at this point in the history
fix(BaseClient): prevent user agent mutation
  • Loading branch information
Jiralite authored Apr 28, 2023
1 parent 40d07fb commit 217e5d8
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions packages/discord.js/src/client/BaseClient.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,19 @@ class BaseClient extends EventEmitter {
throw new DiscordjsTypeError(ErrorCodes.InvalidType, 'options', 'object', true);
}

if (options.rest?.userAgentAppendix) {
// Merging the default options when a custom user agent appendix is supplied
// Replaces the discord.js string. Enforce it.
options.rest.userAgentAppendix = `${Options.userAgentAppendix} ${options.rest.userAgentAppendix}`;
}

/**
* The options the client was instantiated with
* @type {ClientOptions}
*/
this.options = mergeDefault(Options.createDefault(), options);
this.options = mergeDefault(Options.createDefault(), {
...options,
rest: {
...options.rest,
userAgentAppendix: options.rest?.userAgentAppendix
? `${Options.userAgentAppendix} ${options.rest.userAgentAppendix}`
: undefined,
},
});

/**
* The REST manager of the client
Expand Down

0 comments on commit 217e5d8

Please sign in to comment.