Update REST API URL while connected to gateway
Is there a way to update the API URL of a client while it is already connected to the gateway / was initialized already?
65 Replies
- What's your exact discord.js
npm list discord.js
and node node -v
version?
- Not a discord.js issue? Check out #other-js-ts.
- Consider reading #how-to-get-help to improve your question!
- Explain what exactly your issue is.
- Post the full error stack trace, not just the top part!
- Show your code!
- Issue solved? Press the button!
- ā
Marked as resolved by OPIn the rare occasions of my bot being rate limited, I would like to just update the api url
to what?
djs will handle ratelimits for you
I appreciate the concern but this is not about how I handle rate limits for my bot. I'd just like to know how to update a client's api url after init
It sounds specifically like attempting to circumvent rate limits so...
I am running a large bot and a lot of other bots for the largest servers on Discord. Sometimes, unexpected rate limits happen. And because some issues in projects this large can't be fixed within a few minutes or hours, I somehow need to make the bots work again while I am fixing the related issues. Due to the high amount of users affected, waiting hours for a bot to work again is not really an option.
I totally understand if this is not something you'd recommend users to do but I can assure you that I know what I do. Discord already offered increased limits for my bots but highly recommend that I first try to fix the issues myself as they will probably come back due to growth after a while.
Maybe theres something Im missing here. This isnt about whether or not you know what you do, its whether or not you should and if we should support you to do so
We are talking about 200-500 requests per second to Discord here. In the rare occasion of them being invalid, it is not really an option to wait for a few hours until I have found the issue, fixed it and waited for the Cloudflare ban being lifted.. Again, I am not trying to avoid rate limits and misuse Discord's API, I just want to have a backup plan in case I am unable to fix an issue right away.
You do use nirn-proxy right?
Have it clustered with instances on diff vms with diff ips and link it
there is no need for you to do what you questioned
If you do not want to support me with this, this is totally fine, then I'll take a look at the code myself. I just hoped there is a one line solution someone instantly knows here
Since this is a topic better suited for #big-apps , fellow peers should be able to help you there
So what exactly were you hoping to change the API URL to? I guess thats the part Im not understanding
And yeah - much better solutions exist
I do! And this is somewhat what I do already, but nirn-proxy is still letting some 429 through because Discord is inaccurate with their rate limit headers.. I just need a way to quickly switch IPs to make the bots work again, so I can check what caused the issue and fix
if it is something you do
this shouldnt happen
how many instances are using the proxy?
they told you to fix the issue though, I'm not sure how that relates to changing the API url
In my head, nirn-proxy is not that good at preventing rate limits even though most people seem to not get rate limited with it.. is there anything obvious I may be doing wrong?
doing what i told you and considering what nirn proxy does internally, all requests will be routed to those nodes
to my understanding, in a round robin way
just ensure that the nodes are in diff vms with diff ips
or if you have the time, consider looking into kubernetes for this
Imagine your bot gets rate limited once or twice per year and fixing that this rate limit does not occur again in the next hours is not possible due to the huge amount of code that has to be refactored, the only solution to make the bot work instantly after the issue was discovered, is changing its IP. I know that this is not encouraged but I rarely have another choice
Yeah, but simply said: With multiple nirn-proxy instances, you are just hopping from one IP to another. I'd like to implement my own solution for this as this happens too rarely to spend this much money and time on a cluster of proxies
yeah I don't think you can expect much help here if you're explicitly saying that you're not doing what Discord asked you, but a workaround that could be against the ToS
That is to my knowledge, what all >200k+ bots who use nirn proxy do and what you are trying to do is a significantly complex under-taking which you cannot be handheld with
regardless of whether it could be reasonable for your use case, we don't encourage that, only if you contact Discord and they give you permission for that
but they did tell you to do something else so /shrug
So you are suggesting that I just get a bunch of IPs, create a nirn-proxy instance for each of them, connect them all together and then let nirn-proxy handle all requests? I don't trust it as it often does not prevent 429s from going through and I really don't know why
That is, to my knowledge, indeed what is done by majority
But yeah, to my knowledge, too, there is no large Discord bot running on a single IP. This is just impossible
Alright. Thank you. And you don't know much about nirn-proxy not blocking 429s do you? My bot has increased limits already but even when I don't enter them in the nirn-proxy config, it still lets 429s through
Your other option is acquring an ASN range, which as an individual... should be quite hard, but try your luck and get a bag of money ready :rolypoly:
You are located in germany right?
try your luck
im unsure, i have never encountered 429s using nirn
if you want stricter handling, use twilight, it preemptively avoids ratelimits afaik
that's very odd then
What route are you hitting so often that you are getting 429s?
completely different. it was get webhooks for channels before I implemented my own queue. now it just is a wide range of 429s for all kind of endpoints

webhooks act weirdly with nirn yes
in this case i.e., sending messages did 7 req/s as 429 for different channels

:sidelook:
this is really odd
it is
this is not even for the same channel. this rate limit to this endpoint is for all channels. at this point in time, my bot sent about 100 messages in 100 different channels/guilds. This should not be rate limited. I believe that the messages itself are not the ones being rate limited but just this nirn instance reaching 50 req/s
apparently nirn treats as all channels sharing the same bucket?
i dont think this is correct
Also thats not true
your bot should not have a global request limit of 50/s
the one on LBS i mean
LBS?
large bot sharding
large bot sharding
yeah
it does though yeah
What?
as soon as nirn shows 45-50 req/s, all endpoints get 429
per IP
it shouldnt, to my understanding the global req/s is based on concurrency
eg 25 * max_concurrency
unless this behavior has changed?

for large bots i mean
>150k
is this documented?
no
I never heard of that
i have had comms with large bot devs who confirmed this behavior though
unless this behavior has changed
I had the exact different
huh?
i talked to a lot of large bot devs and all they said were they had to talk to staff / mason to get increased limits
i just got this reconfirmed
its manual
that was fast
yeah
ššš
which bot do you run?
a smol 120k bot
alright hahahah
which if you check our dms, you should know š
oh oh that one I missed
Anyways what i can do to help you is limited, try your luck with people that are more intimately experienced with the api in #big-apps or if you are in the private reserved spaces for large bot developers, your needs will be better accommodated there
so sorry. i get like 20 dms per day, it is really hard to keep track
Yeah I will just ask on support.discord.com again
they reply to me there in like 10 minutes with actual useful stuff. the last time I talked with them about this, the issue was not this huge. now it is though
The answer you will receive is most likely the same
so your best bet is what was discussed here
yeah, I will set up a nirn proxy cluster
and try requesting a larger global limit
but will also ask them to increase the global rate limit
that is fine, i do not mind
thank you for your help in here! if you want I can keep you updated in a few weeks time. otherwise you will most likely see it by the status messages in my server, as I can see you are in there haha
i rarely check in on this server ;; i typically only do so when my own expertise falls short in resolving an issue :nodnod: If you would like like a quicker response, feel free to reach out via DM ;; I am more likely to see it there.