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
d.js toolkit
d.js toolkit8mo 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
Luiz
Luiz8mo ago
Yeah upon checking it looks like my proxy isn't setup quite right (Was setup via win11 control panel):
No description
Luiz
Luiz8mo ago
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
Aquinn
Aquinn8mo ago
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
Luiz
Luiz8mo ago
Okay, back at it
No description
Luiz
Luiz8mo ago
looks like the proxy is setup okay however I still get the error
No description
Luiz
Luiz8mo ago
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
No description
Luiz
Luiz8mo ago
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
(async () => {
const resDiscordDNSed = await fetch('https://www.discord.com');
console.log(resDiscordDNSed.status);
})();
(async () => {
const resDiscordDNSed = await fetch('https://www.discord.com');
console.log(resDiscordDNSed.status);
})();
Luiz
Luiz8mo ago
Still yielded the error
No description
Luiz
Luiz8mo ago
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
Luiz
Luiz8mo ago
The below fails:
No description
Luiz
Luiz8mo ago
No description
Luiz
Luiz8mo ago
But using a proxy agent works:
No description
Luiz
Luiz8mo ago
No description
Luiz
Luiz8mo ago
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:
[WS => Shard 0] Connecting to wss://gateway.discord.gg?v=10&encoding=json
[WS => Shard 0] Waiting for event hello for 60000ms
[WS => Shard 0] Failed to connect to the gateway URL specified due to a network error
[WS => Shard 0] The gateway closed with an unexpected code 1006, attempting to reconnect.
[WS => Shard 0] Destroying shard
Reason: none
Code: 1006
Recover: Reconnect
[WS => Shard 0] Connecting to wss://gateway.discord.gg?v=10&encoding=json
[WS => Shard 0] Waiting for event hello for 60000ms
[WS => Shard 0] Failed to connect to the gateway URL specified due to a network error
[WS => Shard 0] The gateway closed with an unexpected code 1006, attempting to reconnect.
[WS => Shard 0] Destroying shard
Reason: none
Code: 1006
Recover: Reconnect
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)