#Fix Connect Timeout Error

29 messages · Page 1 of 1 (latest)

lunar vale
#

Hello, I had this problem too

#

My dev-machine is Windows Server 2019 in Tencent Cloud Shanghai

#

I have opened all firewall ports (1-65535) and allowed any IPV4 inbound and outbound

#
// Require the necessary discord.js classes
const { Client, GatewayIntentBits } = require('discord.js');
const { token } = require('./config.json');

// Create a new client instance
const client = new Client({ intents: [GatewayIntentBits.Guilds] });

// When the client is ready, run this code (only once)
client.once('ready', () => {
    console.log('Ready!');
});

// Login to Discord with your client's token
client.login(token);
untold cedar
#

@teal dragon@lunar vale this still an issue?
if so, that needs some debug logs

@lunar vale doesn't look sharded, so i assume it's not shard specific?

exotic ocean
civic jackal
exotic bear
#

Y sometimes bot crash with that

sand aurora
# exotic ocean

That doesn’t tell us what the request is/was that timed out sadly. Got debug logs of it happening?

civic jackal
#

@exotic ocean , could you add this to your main file:

process.on('uncaughtException', console.trace).on('unhandledRejection', console.trace);
#

And see if it provides a more accurate stack trace

#

If you seen fit, use a bin to send here

bleak burrowBOT
#

To share long code snippets use a service like gist, sourcebin, starbin, or similar instead of posting them as large code blocks.

undone minnow
# exotic ocean

this is unrelated to discord.js, you are using fetch somewhere

civic jackal
#

And the error is fixable by adding a custom agent to rest

undone minnow
#

yes I added undici to djs

#

that error occurs when using fetch; djs uses undici's request

civic jackal
#

Request doesn't use fetch under thw hood?

#

Bc they say the error is fixed when you set a custom agent to the Rest client

#

Doesn't make sense the error beeing outside Rest

civic jackal
undone minnow
#

the error is definitely not from request

#

request doesn't use fetch under the hood

exotic ocean
teal dragon
#

everyone who has updated to discord.js V14 and on console get this: (It's an error about connection time, it seems that it takes time to connect, I don't know what but they should fix it soon)

ConnectTimeoutError: Connect Timeout Error
code: 'UND_ERR_CONNECT_TIMEOUT'
```You can solve it with the following```ts
import { Client } from 'discord.js'
import { Agent } from 'undici'

const client = new Client({ ... })
const agent = new Agent({
  connect: {
    timeout: 30000
  }
})

client.rest.setAgent(agent)

await client.login('...')
near mica
#

Don't think this is related to djs