DiscordJS behind a proxy
I need to use a proxy in order to connect to the internet, however I can't figure out how to get djs to use it.
The package
@discordjs/proxy
doesn't have any documentation (As far as I could see):
https://discord.js.org/docs/packages/proxy/2.0.1
And I'm not running a container, as a package for one was suggested on a similar question. I'm not using multiple instances of my bot, I just can't can't get it do connect due to my proxy. Any help is appreciated, thanks.15 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 OPYeah upon checking it looks like my proxy isn't setup quite right (Was setup via win11 control panel):
I'll try figuring this out and will report back here, thanks
(though www.discord.com works on the browser)
It was set everywhere I could tell on windows, on the new control panel, the old win7 control panel, even set with netsh winhttp set proxy but still no dice
I'll be able to test it further monday
I think this is relevant https://stackoverflow.com/questions/30842894/how-to-setup-node-js-behind-a-corporate-proxy
Stack Overflow
How to setup Node.js behind a corporate proxy
I have installed node.js in my windows machine which is in a corporate network. So i will have to use my Id and password to access internet through the proxy server.
I have read that we can use npm
Okay, back at it
looks like the proxy is setup okay however I still get the error
nslookup reveals that the ip on which the connection was refused resolves from www.discord.com, which I can connect to just fine via curl
This was needed for me to be able to install packages via npm, though I already have and had it configured properly for a while, being able to npm install and all but no dice in connecting my bot
Attempting to run this
Still yielded the error
Update:
Looks like the intended way to do this is to setup a proxy agent and set it on the discord's rest->agent options, which uses undici agents
The below fails:
But using a proxy agent works:
www.discord.com returns status code 301 because maxRedirections is defaulted to 0 on the new agent's options, setting it to a higher value will make the request return a 200 status code
This is working fine http wise, the problem is now the websocket connections:
Final update
There's no real support for doing this, currently, I'm getting it to work by using a third party tool to redirect node.exe traffic through my proxy (I'm using 'ProxyCap' but there are other tools available for windows)