-
-
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
fix: invalid token wrong recognition #10798
base: main
Are you sure you want to change the base?
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎ 2 Skipped Deployments
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remembering that you don't necessarily need to have a webhook to receive this error, it just takes a long time to respond to an interaction, so this wrong condition ends up affecting several bots, especially in Discord API instabilities.
FWIW I'm pretty sure this is wrong. When you respond too slow you get "Unknown interaction", which I assume is a 404, otherwise our issue tracker would probably be getting blown up if we invalidated the token every time you were too slow to respond...
Otherwise, for those webhook routes, the whole point is to pass in auth: false
for routes that don't require the bot's token, i.e. see
discord.js/packages/discord.js/src/structures/Webhook.js
Lines 228 to 233 in ab6a694
const d = await this.client.rest.post(Routes.webhook(this.id, this.token), { | |
body, | |
files, | |
query, | |
auth: false, | |
}); |
and similar callsites from the main library.
All that said, I was not aware of this code 0, but this seems like a pretty nice additional measure that I'm not immediately against.
I apologize, I really expressed myself wrong, this error does not happen when you take too long to respond to the interaction, but when you try to edit an interaction response that has been going on for a long time (15 minutes on my tests), here are 7 interactions routes that use the I didn't know about the existence of auth: false, it probably solves the problem, but I leave my suggestion that code 0 be read to determine if the token is really invalid, we don't know which other routes may end up returning 401 without actually representing an invalid token, I work developing several bots, and some receive this error without actually having an invalid token, I continue to look for the causes, but treating code 0 should solve it. |
The following code does not correctly handle cases where the bot token is invalid:
discord.js/packages/rest/src/lib/handlers/Shared.ts
Lines 141 to 143 in ab6a694
Other requests may return a 401 status, which does not mean that the token is actually invalid. The following request is an example, where the webhook token is invalid, not the bot's token:
Remembering that you don't necessarily need to have a webhook to receive this error, it just takes a long time to respond to an interaction, so this wrong condition ends up affecting several bots, especially in Discord API instabilities.
This commit fixes invalid token wrong detection cases like these, only handling the case where the token is actually invalid, which is when receiving code 0 from the Discord API:
Status and versioning classification: