Closed
Description
Which package is this bug report for?
discord.js
Issue description
The PR #9267 introduced an unexpected behavior when instantiating a new WebhookClient, which extends BaseClient, specifying the userAgentAppendix
.
Specifically, this part of the BaseClient initiation:
discord.js/packages/discord.js/src/client/BaseClient.js
Lines 21 to 25 in 603446a
edits the original
options.rest.userAgentAppendix
prepending Options.userAgentAppendix
. This is fine when instantiating a single Client, but poses problems when instantiating multiple WebhookClients after the initial initiation since the userAgentAppendix
value gets longer and longer each time a new WebhookClient()
is called, to the point where Discord starts returning 400
errors when sending webhooks through any newly instantiated WebhookClient.
This could be solved by deep cloning options
before running:
discord.js/packages/discord.js/src/client/BaseClient.js
Lines 27 to 31 in 603446a
and then moving the above assignment after the deep clone, applied to
this.options
, but deep cloning though JSON.parse/JSON.stringify and structuredClone breaks complex properties of the rest
object, e.g. a custom agent.
Code sample
const clientOptions = { rest: { userAgentAppendix: "loremIpsum/1.0.0" } };
while (true) {
const webhookClient = new WebhookClient({ url: "https://discord.com/api/..." }, clientOptions);
console.log(webhookClient.options.rest.userAgentAppendix);
// userAgentAppendix - and consequently the "user-agent" header - will progressively get bigger: discord.js/14.9.0 Node.js/v18.16.0 discord.js/14.9.0 Node.js/v18.16.0 discord.js/14.9.0 Node.js/v18.16.0 discord.js/14.9.0 Node.js/v18.16.0 discord.js/14.9.0 Node.js/v18.16.0 discord.js/14.9.0 Node.js/v18.16.0 discord.js/14.9.0 Node.js/v18.16.0 discord.js/14.9.0 Node.js/v18.16.0 discord.js/14.9.0 Node.js/v18.16.0 discord.js/14.9.0 Node.js/v18.16.0 discord.js/14.9.0 Node.js/v18.16.0 discord.js/14.9.0 Node.js/v18.16.0 discord.js/14.9.0 Node.js/v18.16.0 discord.js/14.9.0 Node.js/v18.16.0 discord.js/14.9.0 Node.js/v18.16.0 discord.js/14.9.0 Node.js/v18.16.0 discord.js/14.9.0 Node.js/v18.16.0 discord.js/14.9.0 Node.js/v18.16.0 discord.js/14.9.0 Node.js/v18.16.0 [...] discord.js/14.9.0 Node.js/v18.16.0 loremIpsum/1.0.0
}
Package version
14.9.0
Node.js version
18.16.0
Operating system
No response
Priority this issue should have
Medium (should be fixed soon)
Which partials do you have configured?
Not applicable (subpackage bug)
Which gateway intents are you subscribing to?
Not applicable (subpackage bug)
I have tested this issue on a development release
No response