Skip to content

fix(BaseClient): Prevent user agent mutation #9425

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Apr 28, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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