Skip to content

isReady returns false although the client is ready #10493

Open
@GeniusTimo

Description

@GeniusTimo

Which package is this bug report for?

discord.js

Issue description

I wanted to try out if my login retry strategy is working and therefore disabled a privileged gateway intent my bot is requesting on login. This makes it 100 % reproducible but of course this happens too if there are network issues or issues from Discords side on the first login attempt(s)

Steps to reproduce:

  1. Make sure the server members intent is disabled in the developer portal for the bot you're trying to log in to
  2. Start the execution of the code sample below (I used the example main file from the guide as template)
  3. Observe the first one or two failed login attempts
  4. Enable the server members intent in the developer portal again
  5. Observe the successful login attempt

I'd expect the readyClient to return true for isReady() but since PR #9942 got merged it also takes ws.destroyed into account which is still set to destroyed despite the new connection attempt is successful. So this is not a bug introduced in this PR but rather an already exisiting inconsistency with the ws.destroyed not being set back to true when the websocket has successfully connected and is fully operational I believe.

It could also be an implementation error of my retry strategy, but I assumed it's common practice to simply try again via login if it didn't work the first time (of course, with a deeper look at the returned error and not retrying infitite, but I tried to keep the code example as simple as possible)

Code sample

const { Client, Events, GatewayIntentBits } = require('discord.js');
const { token } = require('./config.json');

const client = new Client({ intents: [GatewayIntentBits.Guilds, GatewayIntentBits.GuildMembers] });

client.once(Events.ClientReady, readyClient => {
	console.log(`Ready! Logged in as ${readyClient.user.tag}`);

    console.log(`isReady(): ${readyClient.isReady()}`);
    console.log(`ws.destroyed: ${readyClient.ws.destroyed}`);
});

const loginClient = () => {
    console.log('Attempt to login the client...');

    client.login(token).catch(() => {
        console.log('Attempt to login the client failed');

        setTimeout(() => {
            loginClient();
        }, 10 * 1000);
    });
}

loginClient();

Versions

  • discord.js 14.16.1
  • Node.js 20.17.0

Issue priority

Low (slightly annoying)

Which partials do you have configured?

No Partials

Which gateway intents are you subscribing to?

Guilds, GuildMembers

I have tested this issue on a development release

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions