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
d.js toolkit
d.js toolkit•2d ago
- 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 OP
Xge
XgeOP•2d ago
In the rare occasions of my bot being rate limited, I would like to just update the api url
Amgelo
Amgelo•2d ago
to what? djs will handle ratelimits for you
Xge
XgeOP•2d ago
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
monbrey
monbrey•2d ago
It sounds specifically like attempting to circumvent rate limits so...
Xge
XgeOP•2d ago
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.
monbrey
monbrey•2d ago
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
Xge
XgeOP•2d ago
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.
aris
aris•2d ago
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
Xge
XgeOP•2d ago
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
aris
aris•2d ago
Since this is a topic better suited for #big-apps , fellow peers should be able to help you there
monbrey
monbrey•2d ago
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
Xge
XgeOP•2d ago
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
aris
aris•2d ago
if it is something you do this shouldnt happen how many instances are using the proxy?
Amgelo
Amgelo•2d ago
they told you to fix the issue though, I'm not sure how that relates to changing the API url
Xge
XgeOP•2d ago
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?
aris
aris•2d ago
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
Xge
XgeOP•2d ago
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
Amgelo
Amgelo•2d ago
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
aris
aris•2d ago
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
Amgelo
Amgelo•2d ago
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
Xge
XgeOP•2d ago
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
aris
aris•2d ago
That is, to my knowledge, indeed what is done by majority
Xge
XgeOP•2d ago
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
aris
aris•2d ago
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
Xge
XgeOP•2d ago
that's very odd then
aris
aris•2d ago
What route are you hitting so often that you are getting 429s?
Xge
XgeOP•2d ago
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
No description
aris
aris•2d ago
webhooks act weirdly with nirn yes
Xge
XgeOP•2d ago
in this case i.e., sending messages did 7 req/s as 429 for different channels
No description
aris
aris•2d ago
:sidelook: this is really odd
Xge
XgeOP•2d ago
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
aris
aris•2d ago
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
Xge
XgeOP•2d ago
LBS?
aris
aris•2d ago
large bot sharding
Xge
XgeOP•2d ago
large bot sharding yeah it does though yeah
aris
aris•2d ago
What?
Xge
XgeOP•2d ago
as soon as nirn shows 45-50 req/s, all endpoints get 429 per IP
aris
aris•2d ago
it shouldnt, to my understanding the global req/s is based on concurrency eg 25 * max_concurrency unless this behavior has changed?
Xge
XgeOP•2d ago
No description
aris
aris•2d ago
for large bots i mean >150k
Xge
XgeOP•2d ago
is this documented?
aris
aris•2d ago
no
Xge
XgeOP•2d ago
I never heard of that
aris
aris•2d ago
i have had comms with large bot devs who confirmed this behavior though unless this behavior has changed
Xge
XgeOP•2d ago
I had the exact different
aris
aris•2d ago
huh?
Xge
XgeOP•2d ago
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
aris
aris•2d ago
i just got this reconfirmed its manual
Xge
XgeOP•2d ago
that was fast
aris
aris•2d ago
yeah 😭😭😭
Xge
XgeOP•2d ago
which bot do you run?
aris
aris•2d ago
a smol 120k bot
Xge
XgeOP•2d ago
alright hahahah
aris
aris•2d ago
which if you check our dms, you should know 😭
Xge
XgeOP•2d ago
oh oh that one I missed
aris
aris•2d ago
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
Xge
XgeOP•2d ago
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
aris
aris•2d ago
The answer you will receive is most likely the same so your best bet is what was discussed here
Xge
XgeOP•2d ago
yeah, I will set up a nirn proxy cluster
aris
aris•2d ago
and try requesting a larger global limit
Xge
XgeOP•2d ago
but will also ask them to increase the global rate limit
aris
aris•2d ago
that is fine, i do not mind
Xge
XgeOP•2d ago
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
aris
aris•2d ago
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.

Did you find this page helpful?