Discord.js: Timeout - Shards With Unavailable Guilds Not Starting

Created on 17 Mar 2020  Â·  27Comments  Â·  Source: discordjs/discord.js

Please describe the problem you are having in as much detail as possible:
When I start my bot sharded bot (in 4240 servers), one of the shards times out and stops starting. This issue is persistent across all versions of djs, including 12. The timeout happens around 90% of the time I start the shards. Here are the errors and messages I receive in the console for that shard.

Error: Shard 1's Client took too long to become ready.
Error: Something took too long to do.
Left a guild called undefined.

The last message is me logging the guild leave event, which also seems to be firing from that specific shard.

Include a reproducible code sample here, if possible:

My Sharding File (Code for version 11):

const { ShardingManager } = require('discord.js');
const manager = new ShardingManager('./bot.js', { token: process.env.TOKEN });

manager.spawn(20); // Start 4 Shards
manager.on('launch', shard => console.log("Sharding Manager ➜".bold.brightYellow, `Launched shard ${shard.id}`.bold.brightCyan));

Code for Ready event:

client.login(process.env.TOKEN).catch(console.error)

client.on('ready', (i, callback) => {
    functions.log(`Online in ${client.guilds.size} servers!`)

    blapi.handle(client, apiKeys, 10);

    setTimeout(() => {
        /* Bot Presence (Game and Status) */
        client.shard.fetchClientValues('guilds.size').then(results => {

            let servercount = results.reduce((prev, guildCount) => prev + guildCount, 0)

            client.user.setPresence({
                game: {
                type: 0,
                name: game + " | " + servercount
                //name: 'Discord API Error ➜ https://status.discordapp.com'
                },
                status: status
            });

            if (client.shard.id === 3) {
                Glenn.updateStats(servercount, client.shard.count);
                functions.postStats(client)
                functions.log(`Posted ${servercount} servers!`)
            }
        })
    },60000);
});

The error is persistent across different IP addresses and computers, and I get no email from discord.

Further details:

  • discord.js version: 11.4.2, 11.5.1, 11.6.1, 12, 12.0.2
  • Node.js version: v12.15.0
  • Operating system: Ubuntu & Mac
  • Priority this issue should have – please be realistic and elaborate if possible: Not sure...
  • [x] I have also tested the issue on latest master, commit hash:
unverified gateway sharding bug

Most helpful comment

The workaround for this issue is to manually run triggerReady(). You can do it on a timer like this for example (for v11):

setTimeout(() => {
    client.ws.connection.triggerReady()
},30000)

This will force it to become ready after 30 seconds no matter what.
Not sure if this is the best way to do it, but it seemed to work for many people.

All 27 comments

i have get same error
image

`Error: Something took too long to do.
at timeout.client.setTimeout (/home/bot/node_modules/discord.js/src/client/ClientManager.js:40:57)
at Timeout.setTimeout [as _onTimeout] (/home/bot/node_modules/discord.js/src/client/Client.js:436:7)
at ontimeout (timers.js:498:11)
at tryOnTimeout (timers.js:323:5)
at Timer.listOnTimeout (timers.js:290:5)

(node:24888) UnhandledPromiseRejectionWarning: Error: Shard 33's Client disconnected before becoming ready.
at Shard.once (/home/bot/node_modules/discord.js/src/sharding/Shard.js:87:44)
at Object.onceWrapper (events.js:313:30)
at emitNone (events.js:106:13)
at Shard.emit (events.js:208:7)
at Shard._handleMessage (/home/bot/node_modules/discord.js/src/sharding/Shard.js:211:14)
at emitTwo (events.js:126:13)
at ChildProcess.emit (events.js:214:7)
at emit (internal/child_process.js:762:12)
at _combinedTickCallback (internal/process/next_tick.js:142:11)
at process._tickCallback (internal/process/next_tick.js:181:9)`

Noticed the exact same issues yesterday on a ShardingManager running 11 shards.

It really hurts my userbase.
Please help!

This seems to have to do with shards with unavalible guilds, which would explain leaving an undefined guild. These may have increased due to an increase in Discord users due to Covid-19

Pressed close instead of comment, whoops!

Same issue here. Seems to be indeed unavailable guilds causing this.

the unavailable guilds seems to completely stop bots from connecting shaded or not

Running an small bot (no shards) and it's unable to start because of this. I have to manually reset it until it becomes available again.

Same issue here.

The workaround for this issue is to manually run triggerReady(). You can do it on a timer like this for example (for v11):

setTimeout(() => {
    client.ws.connection.triggerReady()
},30000)

This will force it to become ready after 30 seconds no matter what.
Not sure if this is the best way to do it, but it seemed to work for many people.

The workaround for this issue is to manually run triggerReady(). You can do it on a timer like this for example (for v11):

setTimeout(() => {
    client.ws.connection.triggerReady()
},30000)

This will force it to become ready after 30 seconds no matter what.
Not sure if this is the best way to do it, but it seemed to work for many people.

Can confirm that this solved my problem for now. The broken shard is working again.

The workaround for this issue is to manually run triggerReady(). You can do it on a timer like this for example (for v11):

setTimeout(() => {
    client.ws.connection.triggerReady()
},30000)

This will force it to become ready after 30 seconds no matter what.
Not sure if this is the best way to do it, but it seemed to work for many people.

where should i put this

where should i put this

anywhere in your bot's main file, ie:

let client = new Discord.Client();

setTimeout(() => {
    client.ws.connection.triggerReady()
},30000)

client.login();

where should i put this

anywhere in your bot's main file, ie:

let client = new Discord.Client();

setTimeout(() => {
    client.ws.connection.triggerReady()
},30000)

client.login();

thx

This issue is an issue for version 11 which should be fixed in version 12 according to the DJS staff.

Solution:
Quoting @timotejroiko:

The workaround for this issue is to manually run triggerReady(). You can do it on a timer like this for example (for v11):

setTimeout(() => {
    client.ws.connection.triggerReady()
},30000)

This will force it to become ready after 30 seconds no matter what.
Not sure if this is the best way to do it, but it seemed to work for many people.

I'm closing this thread now!

This is definitely not a "real" solution. Hence keeping it open.

If it is true, that it is fixed in v12, then this is a real solution and can be closed i'd say.

discord.js v12.1.1

Error [SHARDING_READY_TIMEOUT]: Shard 10's Client took too long to become ready.
    at Timeout.onTimeout (/home/bot/node_modules/discord.js/src/sharding/Shard.js:160:16)
    at listOnTimeout (internal/timers.js:549:17)
    at processTimers (internal/timers.js:492:7) {
  [Symbol(code)]: 'SHARDING_READY_TIMEOUT'
}

Any update/fix on this?

Not currently, but a temporary solution is above for version 11:

The workaround for this issue is to manually run triggerReady(). You can do it on a timer like this for example (for v11):

setTimeout(() => {
    client.ws.connection.triggerReady()
},30000)

This will force it to become ready after 30 seconds no matter what.
Not sure if this is the best way to do it, but it seemed to work for many people.

Is there any way for version 12?

Getting this error in v12.1.1

+1

Got this error in the latest 12.2.0. Here are my findings after a bit of testing:

I have overridden the default timeout via shardingManager.spawn(shardingManager.totalShards, 5500, -1);.

As stated in hte source code, setting the last parameter to -1 will disable the timeout completely. The other parameters are the default values.

I now no longer get the error message. However, the shards are not getting online at all.

manager.on('launch', shard => {
    console.log("=== Launched shard " + shard.id);
});

is not getting triggered and my bot is listed as offline, even after waiting for well over 10 minutes.

This indicates that there is an issue with the login itself. According to Discord's changelog, there has been no API changes since March 3rd.
I have then verified my token on the developer portal. I regenerated the token and used a newly created one in case my old token got banned.

Still my bot won't come online no matter how long I wait.

After all this, it seems to me that there is a bigger underlying issue here.

There no longer is a 'launch' event on v12, the only event the sharding manager currently has is 'shardCreate', see ShardingManager#shardCreate.

Without further info (read: logs) there is nothing that can be done about this really.

Probably relevant to log:

Thank you @SpaceEEC for the information.

Client#debug produced a helpful log:

[...]
[4/26/2020 10:13:34 PM]  [WS => Manager] Fetched Gateway Information
    URL: wss://gateway.discord.gg
    Recommended Shards: 11
[4/26/2020 10:13:34 PM]  [WS => Manager] Session Limit Information
    Total: 1000
    Remaining: 0
[4/26/2020 10:13:34 PM]  [WS => Manager] Spawning shards: 0
[4/26/2020 10:13:34 PM]  [WS => Manager] Exceeded identify threshold. Will attempt a connection in 13919462ms
[...]

In my case, my bot did a bootloop in the middle of the night, causing Discord to ratelimit my app for 24h according to their documentation.
I will edit this reply as soon as I have tested again by tomorrow.

Getting this on v12.3.1

Same issue still in 12. "triggerready" does not function in 12 so that's not a solution unfortunately.

Was this page helpful?
1 / 5 - 1 ratings

Related issues

smchase picture smchase  Â·  3Comments

tiritto picture tiritto  Â·  3Comments

PassTheMayo picture PassTheMayo  Â·  3Comments

BrandonCookeDev picture BrandonCookeDev  Â·  3Comments

Lombra picture Lombra  Â·  3Comments