Please describe the problem you are having in as much detail as possible:
The Login promise will resolve before the Ready event is generated.
Maybe this is the wanted behaviour ? I'm not sure, it feels odd to me.
Include a reproducible code sample here, if possible:
try {
// Login the client to the Discord API
await bot.login(env.DISCORD_TOKEN)
// On Ready runs about here but on this line it may not have generated the ready event yet so any code here will not see the guilds as the bot is not truly connected.
// Although it will work on small test Discords I ran the same code on a bot that run on 3, 2000+ members Discord and the first Discord was not ready when that line ran, but the 2 after were actually ready.
} catch (err) {
console.error("ERROR : An error occurred during login, ABORTING !", err)
process.exit(21)
}
// True Ready state
bot.on("ready", () => {
// The bot is truly logged in at this point.
})
Further details:
This is pretty much exactly why the ready event exists.
The process of initialising the bot is much more than a login - it identifies with the gateway and Discord.js populates it's Collections with the data received (guilds, channels, etc).
Most helpful comment
This is pretty much exactly why the ready event exists.
The process of initialising the bot is much more than a login - it identifies with the gateway and Discord.js populates it's Collections with the data received (guilds, channels, etc).