-
Notifications
You must be signed in to change notification settings - Fork 31
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
Use with discord.py bot #57
Comments
As is stated in the README, the proxy replaces the Discord API instead of serving as a real HTTP CONNECT proxy. You're using it as if it were a HTTP CONNECT proxy, which is unsupported. |
Aw, that's too bad. I was hoping that https://fusebit.io/blog/discord-rate-limiting/ knew what it was talking about, but apparently it doesn't. Thanks for the heads up. I might as well ask: Do you know of any real http proxies for Discord bots? |
I don't know of any proper proxies, but it is probably our own fault for the name. You can get it working with discord.py by monkeypatching |
It is practically impossible to use a real HTTP CONNECT proxy for this from what I know about the CONNECT protocol. You see, the client only specifies the host and port to open a connection with, and all the traffic itself is then tunneled. The issue is that if SSL is being used, which it would in this case, the proxy won't be able to tell which exact URLs are being requested. It will know that |
This is the bare minimum - if you want to hand full control to the proxy, you could use something like this patch as a base to get rid off local rate limit handling and leave everything to the proxy. |
Thank you so much, y'all have been super helpful ❤️ 🤔 This seems to work ok: def patch_discord_proxy(PROXY_URL: str):
"""Patch discord.http to use our Discord API proxy."""
from discord import http
http.Route.BASE = f"{PROXY_URL}/api/v10"
http._set_api_version = lambda v: f"{PROXY_URL}/api/v{v}" @Gelbpunkt I see you did similar, but also ripped out a lot of discord.py's own rate limiting. That makes sense, for sure. But for the most part discord.py's rate limiting works fine for me. It's just the global rate limiting that discord.py is awful about handling. Rather than proactively prevent the bot from hitting the global rate limit, it just reacts to the rate limit being hit by shutting the bot down until the 1 hour CloudFlare ban wears off. IIUC twilight's http-proxy will actually stop the requests from going out, queue them up, and then resume them later to avoid the 50 requests/s CloudFlare limit. Is that right? Maybe I can just use my quick and dirty patch + twilight-http-proxy to get that nice proactive intelligent global rate limiting feature, and just leave all the discord.py rate limiting stuff in there (which hopefully won't hurt anything 🤞🏻)? |
It will hold your connection and send the request to Discord once it won't be ratelimited. Therefore you might run into timeouts if the client is configured with a low timeout.
You can and it will certainly work. I just don't see a reason to have overhead in Python code, based on limited knowledge, instead of just leaving everything to the proxy, because it does these computations already. That said, what you are doing will work fine, so no need to worry about that. |
Hrm, something didn't work. I am currently getting the dreaded Did I misconfigure something? I see no logs for
|
No it probably is correct. The issue here is that we do not preemptively handle the global rate limit see twilight-rs/twilight#650 |
Closing this since it looks like this issue is resolved/related to twilight-rs/twilight#650. |
I'm on a M1 mac so I wasn't able to get it to work via docker. But I cloned this repo then:
cargo build --release DISCORD_TOKEN="my token" PORT=3000 ./target/release/twilight-http-proxy 2022-06-22T15:52:23.122150Z INFO twilight_http_proxy: Listening on http://0.0.0.0:3000
Now I start up my bot using
proxy="http://localhost:3000"
and I immediately have issues. In the proxy log I see:And in my bot's log we can see that it's trying to
GET /users/@me
:The text was updated successfully, but these errors were encountered: