-
-
Notifications
You must be signed in to change notification settings - Fork 4k
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
userAgentAppendix appended multiple times to REST user-agent header each time WebhookClient is instantiated #9421
Comments
Hi, thank you for the report. I copied your code sample and I am monitoring the requests via Undici: import diagnosticsChannel from "node:diagnostics_channel";
import { WebhookClient } from "discord.js";
diagnosticsChannel.channel("undici:request:create").subscribe(({ request }) => {
console.log(request.headers); // Log the headers.
});
while (true) {
const webhookClient = new WebhookClient(
{ url: "https://discord.com/api/..." },
{ rest: { userAgentAppendix: "loremIpsum/1.0.0" } },
);
await webhookClient.send("Hello there");
} The diagnostics channel is reporting the same user agent for each request (on 14.9.0 and ecd1b5d):
I seem to not be able to reproduce this. Is there any other missing information, or perhaps the code sample was malformed? |
You are right, the example code was malformed. The point of the bug is that the options object is edited on each iteration, passing a plain object created a clean situation each time. |
I see the mutation crystal clear now. Thank you!
I think you might need to move |
Done and thanks! |
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
prependingOptions.userAgentAppendix
. This is fine when instantiating a single Client, but poses problems when instantiating multiple WebhookClients after the initial initiation since theuserAgentAppendix
value gets longer and longer each time anew WebhookClient()
is called, to the point where Discord starts returning400
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 therest
object, e.g. a custom agent.Code sample
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
The text was updated successfully, but these errors were encountered: