discord.js
discord.js copied to clipboard
Getting ratelimited
Please describe the problem you are having in as much detail as possible: I am getting ratelimited by discord for an unknown reason As said here it should never happen but I do not know why this is happening for me https://github.com/discordjs/discord.js/blob/6be5051f9296fe9a10549f2f9a11c18776b1b617/src/rest/RequestHandler.js#L149
For more information, it's happening frequently at 00:00 GMT
I am also having a lot of 500 errors when this is happening.
Include a reproducible code sample here, if possible:
429 hit on route /gateway/bot
Code : 500
AbortError: The user aborted a request.
at RequestHandler.execute (/home/koyamie/Koya/node_modules/discord.js/src/rest/RequestHandler.js:106:9)
at runMicrotasks (<anonymous>)
at processTicksAndRejections (internal/process/task_queues.js:93:5)
Further details:
- discord.js version: lastest master
- Node.js version: 12.13.0
- Operating system: debian 9
- Priority this issue should have – please be realistic and elaborate if possible:
- [x] I have also tested the issue on latest master, commit hash:
Hello, kinda high issue, happening everyday since I updated the repo (was on a september commit)
Is it possible you hit the max of 1000 logins per day? Have you tried listening on the debug event?
Is it possible you hit the max of 1000 logins per day? Have you tried listening on the debug event?
Nope, when I am hitting 1k logins a day its different, I can't login for 24 hours and debugging tells how many time I have to wait, here I am getting a 429 "Too many requests" and debugging only shows this : "429 hit on route /gateway/bot"
If you need help with discord.js installation or usage, please go to the discord.js Discord server instead: https://discord.gg/bRCvFy9 This issue tracker is only for bug reports and enhancement suggestions.
Since this is happening at exactly 0:00 it would seem there's some scheduled task running at this time causing it. We can investigate further on Discord.
If you need help with discord.js installation or usage, please go to the discord.js Discord server instead: https://discord.gg/bRCvFy9 This issue tracker is only for bug reports and enhancement suggestions.
Since this is happening at exactly 0:00 it would seem there's some scheduled task running at this time causing it. We can investigate further on Discord.
Yeah but, as the line is saying "This should never happen" I guess this is related to the lib.
i could imagine that this might be related to multiple Shards/Clients fetching the /bot/gateway endpoint at the same time and since they dont know of each other they do too many requests and hit the ratelimit, are you sure you dont fetch the /bot/gateway endpoint on your own? because d.js should only ever fetch that on startup and i can't imagine that your bot restarts everytime on 0:00 GMT
i could imagine that this might be related to multiple Shards/Clients fetching the /bot/gateway endpoint at the same time and since they dont know of each other they do too many requests and hit the ratelimit, are you sure you dont fetch the /bot/gateway endpoint on your own? because d.js should only ever fetch that on startup and i can't imagine that your bot restarts everytime on 0:00 GMT
I think too but I have no reason fetching this endpoint on my own. Yup my bot isn't restarting everytime but at 0:00 GMT my game timestamps reset (like the tatsumaki daily and reputation) but there is no reason that it fetch this endpoint 🤔 This is weird
Okay i just looked in the src and saw that d.js actuall does call the /bot/gateway endpoint everytime it reconnects (this shouldn't be like that) and since you mentioned that you get these every day at 0:00 GMT this probaly means that your bot reconnects every day at that time (maybe related to your host?) sadly d.js does always fetch the session endpoint even when resuming a session but vlad actuall fixed that in #3393 so you could give this pr a try since it should fix your issue (he changed it so it only fetches /gateway/bot if no session_id id present).
Also you should probaly check why the bot reconnects everytime at 00:00 GMT, do you maybe change your ip or does your isp/host do that? i would recommend looking into that.
Even tho #3393 probaly fixes this issue i will open another one because the current implementation is very poor designed for bots using any ShardingManager and this needs to be changed since we currently do not handle ratelimits for /gateway/bot across shards.
Okay i just looked in the src and saw that d.js actuall does call the /bot/gateway endpoint everytime it reconnects (this shouldn't be like that) and since you mentioned that you get these every day at 0:00 GMT this probaly means that your bot reconnects every day at that time (maybe related to your host?) sadly d.js does always fetch the session endpoint even when resuming a session but vlad actuall fixed that in #3393 so you could give this pr a try since it should fix your issue (he changed it so it only fetches /gateway/bot if no session_id id present).
Also you should probaly check why the bot reconnects everytime at 00:00 GMT, do you maybe change your ip or does your isp/host do that? i would recommend looking into that.
Even tho #3393 probaly fixes this issue i will open another one because the current implementation is very poor designed for bots using any ShardingManager and this needs to be changed since we currently do not handle ratelimits for /gateway/bot across shards.
This is was I thought, I will give a try to this PR and check tonight if it is happening again and will update the issue. My bot is not reconnecting at 0:00 this is why I do not understand 😯
Okay i just looked in the src and saw that d.js actuall does call the /bot/gateway endpoint everytime it reconnects (this shouldn't be like that) and since you mentioned that you get these every day at 0:00 GMT this probaly means that your bot reconnects every day at that time (maybe related to your host?) sadly d.js does always fetch the session endpoint even when resuming a session but vlad actuall fixed that in #3393 so you could give this pr a try since it should fix your issue (he changed it so it only fetches /gateway/bot if no session_id id present). Also you should probaly check why the bot reconnects everytime at 00:00 GMT, do you maybe change your ip or does your isp/host do that? i would recommend looking into that. Even tho #3393 probaly fixes this issue i will open another one because the current implementation is very poor designed for bots using any ShardingManager and this needs to be changed since we currently do not handle ratelimits for /gateway/bot across shards.
This is was I thought, I will give a try to this PR and check tonight if it is happening again and will update the issue. My bot is not reconnecting at 0:00 this is why I do not understand 😯
Are you sure about this? because it very much looks like it (reconnecting does not only include re-identifying but also resuming a session) can you make sure and listen to the shardReconnecting
event (e.g log it to the console or somehow notify yourself) and update this post once you tested it?
Update : I started debugging tonight to see what happen at 0:00 GMT, I found what in my bot was getting me ratelimited for 1h.
I was hitting 429 very very many times but with different enpoints, the most I saw was /channels/ID/messages
this one should be fixed in my code but still hitting 429 even if it should never happen.
I havn't tried the PR because I got no time yesterday.
Anyway, I'll keep this issue open until we get a fix on master.
You are being very vague about this.
/channels/Id/messages
, doesn't mean a lot. This needs more information on your part, maybe even some code samples of what your usage is and why you are hitting it.
It would be nice if this is getting a bit more context.
If you get ratelimited on other routes e.g /channels/ID/messages
you might hit the Global Ratelimit and then hitting a 429 is normal but then there is still the question why you hit /gateway/bot
aswell at that time 🤔
You are being very vague about this.
/channels/Id/messages
, doesn't mean a lot. This needs more information on your part, maybe even some code samples of what your usage is and why you are hitting it.It would be nice if this is getting a bit more context.
Yes very sorry will explain better as soon as I can
If you get ratelimited on other routes e.g
/channels/ID/messages
you might hit the Global Ratelimit and then hitting a 429 is normal but then there is still the question why you hit/gateway/bot
aswell at that time 🤔
Maybe hitting it too much result to a gateway ban for 1 hour (Can't connect for 1 hour everytime it happens)
Hello, this is happening today but in different way, restarted my bot after making changes and now bot is having very difficulties to connect and I am hitting 429 way too much (I should never hit 429 remember)
Any help ?
Could be a possible API issue (https://status.discordapp.com/) but still, I should not hit 429
Hello, it happened again tonight with discord increased API response time. Any news for this ?
UP
Having the same issue here now.
429 hit on route /gateway/bot
Have 0 idea this has never happened before.
very frustrating
If it happens once or a few times and you're sharded across multiple processes, it happens. If it's spammed, it's an issue.
d.js version, node.js version please!
Discord.js ^12.2.0 Node.js 11.x
It isnt spammed, just happens every minute or so.
Discord.js ^12.2.0 Node.js 11.x
Discord.js v12 has a minimum Node version of v12 also. This doesn't line up
it worked for 3 months originally?
Even me bot the problem. But i was just connected like 10 times
429 hit on route /gateway/bot
429 hit on route /gateway/bot
429 hit on route /gateway/bot
429 hit on route /gateway/bot
429 hit on route /gateway/bot
429 hit on route /gateway/bot
429 hit on route /gateway/bot
429 hit on route /gateway/bot
429 hit on route /gateway/bot
429 hit on route /gateway/bot
429 hit on route /gateway/bot
429 hit on route /gateway/bot
429 hit on route /gateway/bot
429 hit on route /gateway/bot
429 hit on route /gateway/bot
429 hit on route /gateway/bot
429 hit on route /gateway/bot
429 hit on route /gateway/bot
429 hit on route /gateway/bot
Node Engine: 12.x Discord.js: ^12.2.0
My project is not working on Any Bot Tokens Pls help everybots getting strucked at
Provided token: NzEwODE2MTI3MTA5OTU1NjA1.XsOUQw.***************************
Preparing to connect to the gateway...
429 hit on route /gateway/bot
I Don't what I want to do. also I just logging one time in my project
My project is not working on Any Bot Tokens Pls help everybots getting strucked at
Provided token: NzEwODE2MTI3MTA5OTU1NjA1.XsOUQw.*************************** Preparing to connect to the gateway... 429 hit on route /gateway/bot
I Don't what I want to do. also I just logging one time in my project
You are IP banned for 1 hour, just wait and retry.
Thanks! I will try after 1 hour
The ip was banned forever i think even it not worked now. I was using glitch.com to run my bot
- Node.js v12.18.2
- discord.js v12.3.1
Suddenly the bot did not respond without any error, and when I restarted the bot and tried to client login again, it did not login without any error. When I called the Discord API directly from the server, I found out that Discord blocked it.
curl https://discord.com/api/v6
{"code": 0, "message": "You are being blocked from accessing our API temporarily due to exceeding our rate limits frequently. Please read our docs at https://discord.com/developers/docs/topics/rate-limits to prevent this moving forward."}
When I tried again after an hour, it would be nice if the bot was logged in but got an error saying it was blocked in Discord.
I was running into this problem for... a very long time (dating back to mid march). Here are some sparse error logs. I reached out to a Discord staff member in the Discord Developers server and they said a bot on my network was consistently hitting rate limits and that led to a one hour CloudFlare ban.
In the end, I decided to migrate two of my larger bots (300 & 900 guilds) from my local machines ~ into the cloud ~ and that seemed to mitigate the problem entirely -- haven't ran into any bans since.
tldr: hoarding multiple bots on a single network should be avoided
For me, it keeps spamming. It's a serious problem for me, bot goes down for an hour. And users shouting lol. Seems to be a bug on Discord's end, since the retry after header is incorrect and so the lib keeps trying to reconnect. This starts happening with a similar rate limit, on channels something route, it spams it and then gets IP banned. I'm sure discord.js is handling rate-limits correctly and I'm not doing any API Request outside lib. In that channel rate limit too, even after the retry after time span ends, it's still getting rate limit headers, so probably Discord giving out wrong values for rate-limits? Some info. I'm only hosting one bot on the VPS. My bot is in 330 ~ guilds, and not sharded of course. My bot usually hits limits on messages because of how it should actually work lol, but that shouldn't be an issue since Discord.js handles rate limits correctly. I'll look further to contact with Discord about this issue if this comment isn't getting noticed.. since people on the Discord.js server have been ignorant anyway. This never happened to me before, just started happening since a week and it's like happening every 2-3rd day. You might be curious how am I so sure about "incorrect rate limit headers", I had modified src/RequestHandler.js and added some more info to the log from the headers (and body too, showing that its IP Banned). If you're curious what code I added, here it is:
} else if (res.status === 429) {
// A ratelimit was hit - this should never happen
this.queue.unshift(item);
let body = await res.text();
this.manager.client.emit('debug', `429 hit on route ${item.request.route} - rate limit ${this.limit} - retry after ${this.retryAfter} - reset ${this.reset} - remainaing ${this.remaining} - global ${(this.manager.globalTimeout}\nResponse Body: ${body}`);
await Util.delayFor(this.retryAfter);
return this.run();
About the logs I see in console from this rate limit:
Hope it helps to identify.. would appreciate if this issue is resolved..
Discord.js Version => 12.3.1 Node.js Version => 12.18.2