aiko-chan-ai / discord.js-selfbot-v13

An unofficial discord.js fork for creating selfbots
https://discordjs-self-v13.netlify.app
GNU General Public License v3.0
777 stars 165 forks source link

Proxy not work #1043

Closed wujohns closed 3 months ago

wujohns commented 8 months ago

Which package has the bugs?

The core library

Issue description

The proxy example not work

Code sample

No response

Package version

3.1.4

Node.js version

v18.14.2

Operating system

No response

Priority this issue should have

High (immediate attention needed)

Checklist

Additional Information

I have reviewed the code, and find the bug reason:

  1. the module 'proxy-agent' not work at all (always timeout)
  2. when change the proxy module from 'proxy-agent' to 'https-proxy-agent', the agent object can work
  3. for 2, need change follow codes:
// src/rest/APIRequest.js 
...
make(captchaKey, captchaRqToken) {
    if (!agent) {
      // if (this.client.options.http.agent instanceof http.Agent) {
      if (this.client.options.http.agent) {
        this.client.options.http.agent.options.keepAlive = true;
...
// src/client/websocket/WebSocketShard.js
...
      const ws = (this.connection = WebSocket.create(gateway, wsQuery, {
        handshakeTimeout: 30_000,
        agent: client.options.ws.agent
        // agent: client.options.ws.agent instanceof http.Agent ? client.options.ws.agent : undefined,
      }));
...
wujohns commented 8 months ago

because the agent module 'https-proxy-agent' works fine, but 'https-proxy-agent' is not instanceof http.Agent

wujohns commented 8 months ago

May I make a pr for this?

aiko-chan-ai commented 8 months ago

because the agent module 'https-proxy-agent' works fine, but 'https-proxy-agent' is not instanceof http.Agent

https://github.com/TooTallNate/proxy-agents/blob/main/packages/https-proxy-agent/src/index.ts#L44 https://github.com/TooTallNate/proxy-agents/blob/main/packages/agent-base/src/index.ts#L29

wujohns commented 8 months ago

because the agent module 'https-proxy-agent' works fine, but 'https-proxy-agent' is not instanceof http.Agent

https://github.com/TooTallNate/proxy-agents/blob/main/packages/https-proxy-agent/src/index.ts#L44 https://github.com/TooTallNate/proxy-agents/blob/main/packages/agent-base/src/index.ts#L29

emmmmm,but the example code not work..... I just try to find the way which can work

wujohns commented 8 months ago

because the agent module 'https-proxy-agent' works fine, but 'https-proxy-agent' is not instanceof http.Agent

https://github.com/TooTallNate/proxy-agents/blob/main/packages/https-proxy-agent/src/index.ts#L44 https://github.com/TooTallNate/proxy-agents/blob/main/packages/agent-base/src/index.ts#L29

The main problem is the npm module 'proxy-agent' has bug, even their code is beautiful but not work at all

wujohns commented 8 months ago

my agent object is below:

const HttpsProxyAgent = require('https-proxy-agent')
const httpAgent = new HttpsProxyAgent('http://127.0.0.1:7890')
const wsAgent = new HttpsProxyAgent('http://127.0.0.1:7890')

const client = new Client({
  http: { agent: httpAgent },
  ws: { agent: wsAgent }
})

this agent can link the discord server correctly and using the proxy which I set

wujohns commented 8 months ago

when using npm module 'proxy-agent' the link to discord always failed The code below not work:

const { ProxyAgent } = require('proxy-agent')
const httpAgent = new ProxyAgent('http://127.0.0.1:7890')
const wsAgent = new ProxyAgent('http://127.0.0.1:7890')

const client = new Client({
  http: { agent: httpAgent },
  ws: { agent: wsAgent }
})

for this example: https://github.com/aiko-chan-ai/discord.js-selfbot-v13/blob/main/examples/Proxy.js

wujohns commented 8 months ago

But:

  1. the npm module 'https-proxy-agent' is not the instance of http.Agent (this.client.options.http.agent instanceof http.Agent is false),
  2. so I fork this repo, and change the instance of http.Agent judge code
  3. for 2, the temp change is work fine for me
  4. so may I need make a pr for this

commit: https://github.com/wujohns/discord.js-selfbot-v13/commit/1db27dd03444938cb483ddf6406c325a6555b5b4

aiko-chan-ai commented 8 months ago

I will review it later

phatdev12 commented 8 months ago

when using npm module 'proxy-agent' the link to discord always failed The code below not work:

const { ProxyAgent } = require('proxy-agent')
const httpAgent = new ProxyAgent('http://127.0.0.1:7890')
const wsAgent = new ProxyAgent('http://127.0.0.1:7890')

const client = new Client({
  http: { agent: httpAgent },
  ws: { agent: wsAgent }
})

for this example: https://github.com/aiko-chan-ai/discord.js-selfbot-v13/blob/main/examples/Proxy.js

So....Why is my side operating normally?

wujohns commented 8 months ago

when using npm module 'proxy-agent' the link to discord always failed The code below not work:

const { ProxyAgent } = require('proxy-agent')
const httpAgent = new ProxyAgent('http://127.0.0.1:7890')
const wsAgent = new ProxyAgent('http://127.0.0.1:7890')

const client = new Client({
  http: { agent: httpAgent },
  ws: { agent: wsAgent }
})

for this example: https://github.com/aiko-chan-ai/discord.js-selfbot-v13/blob/main/examples/Proxy.js

So....Why is my side operating normally?

maybe your network can link the discord directly, in my side it's always timeout

phatdev12 commented 8 months ago

when using npm module 'proxy-agent' the link to discord always failed The code below not work:

const { ProxyAgent } = require('proxy-agent')
const httpAgent = new ProxyAgent('http://127.0.0.1:7890')
const wsAgent = new ProxyAgent('http://127.0.0.1:7890')

const client = new Client({
  http: { agent: httpAgent },
  ws: { agent: wsAgent }
})

for this example: https://github.com/aiko-chan-ai/discord.js-selfbot-v13/blob/main/examples/Proxy.js

So....Why is my side operating normally?

maybe your network can link the discord directly, in my side it's always timeout

hmm why https-proxy-agent works fine. it's so strange

phatdev12 commented 8 months ago

https-proxy-agent

image

proxy-agent

image

i checked both sides and it's pretty much the same. hmmm

phatdev12 commented 8 months ago

fact

image In proxy-agent

Cosmin19543 commented 7 months ago

proxy-agent does not work. https-proxy-agent works but its slower apparently. So yes, the example does not work.

Cosmin19543 commented 1 month ago

The proxy.js example does not work