From 217e5d81005a2506c96335f7fb96fa21d7dbb04c Mon Sep 17 00:00:00 2001 From: Jiralite <33201955+Jiralite@users.noreply.github.com> Date: Fri, 28 Apr 2023 18:46:50 +0100 Subject: [PATCH] fix(BaseClient): Prevent user agent mutation (#9425) fix(BaseClient): prevent user agent mutation --- packages/discord.js/src/client/BaseClient.js | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/packages/discord.js/src/client/BaseClient.js b/packages/discord.js/src/client/BaseClient.js index 65e19c25309b..91c6afac3677 100644 --- a/packages/discord.js/src/client/BaseClient.js +++ b/packages/discord.js/src/client/BaseClient.js @@ -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