Fix Connect Timeout Error

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'
ConnectTimeoutError: Connect Timeout Error
code: 'UND_ERR_CONNECT_TIMEOUT'
You can solve it with the following
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('...')
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('...')
15 Replies
probablyraging
Don't think this is related to djs
Unknown User
Unknown User3y ago
Message Not Public
Sign In & Join Server To View
souji
souji3y ago
@srgobi@是乐浅浅啊 this still an issue? if so, that needs some debug logs @是乐浅浅啊 doesn't look sharded, so i assume it's not shard specific?
Unknown User
Unknown User3y ago
Message Not Public
Sign In & Join Server To View
조아오
조아오3y ago
Can you specify the exact request thats timeout or if it is all of them??
LeStyloBleu
LeStyloBleu3y ago
Y sometimes bot crash with that
Unknown User
Unknown User3y ago
Message Not Public
Sign In & Join Server To View
조아오
조아오3y ago
@zenomic , could you add this to your main file:
process.on('uncaughtException', console.trace).on('unhandledRejection', console.trace);
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
d.js docs
d.js docs3y ago
To share long code snippets use a service like gist, sourcebin, starbin, or similar instead of posting them as large code blocks.
Unknown User
Unknown User3y ago
Message Not Public
Sign In & Join Server To View
조아오
조아오3y ago
Wdym? Bc djs uses undici under the hood And the error is fixable by adding a custom agent to rest
Unknown User
Unknown User3y ago
Message Not Public
Sign In & Join Server To View
조아오
조아오3y ago
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 Nice
Unknown User
Unknown User3y ago
Message Not Public
Sign In & Join Server To View
조아오
조아오3y ago
Okay, thanks peepoLoveMonbrey
Want results from more Discord servers?
Add your server