discordjs / discord.js

A powerful JavaScript library for interacting with the Discord API
https://discord.js.org
Apache License 2.0
25.36k stars 3.97k forks source link

Rest resets tokens even when it shouldn't #9196

Closed AwesomeStickz closed 1 year ago

AwesomeStickz commented 1 year ago

Which package is this bug report for?

discord.js

Issue description

By default, if rest sees a 401 at all, it's resetting the token you set: https://github.com/discordjs/discord.js/blob/dc142c47e4021d6d37712453cc2fad6e4fe4e9f7/packages/rest/src/lib/handlers/SequentialHandler.ts#L492

This isn't the expected behavior for every requests. There are webhook requests which could also end up in a 401 status code (for example interaction webhooks), which means rest will set the token to null, even though the bot token is completely still fine so this isn't the expected result

I'm not sure about exact ways to reproduce this, so I'm not providing code sample but just wanted to bring this issue into attention, I mostly only use interactions and normal auth endpoints (no oauth), it happens in between them often so I can confirm it's doing that from one interaction and then for further requests, the token is null (given you only set at first in new REST() and not in each request)

Code sample

No response

Package version

@discordjs/rest - v1.5.0

Node.js version

18.10.0

Operating system

Ubuntu

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

Jiralite commented 1 year ago

Are you using /rest on its own? This was marked as a discord.js bug but you provided a /rest version?

In any case, look 1 line above. These API methods do not require authentication, so you should be passing auth: false. This should not occur.

AwesomeStickz commented 1 year ago

I use only /rest on its own, yes.

Actually totally missed that auth part and only looked at the status part, my bad, I didn't notice the auth option and was just not using it at all, ty for letting me know! (tho it would've been nice if rest itself picks it up for certain endpoints but I see you created an issue on that one so it should be good now)