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'
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('...')
Was this page helpful?