timotejroiko / discord.js-light

All the power of discord.js, zero caching. This library modifies discord.js's internal classes and functions in order to give you full control over its caching behaviour.
Apache License 2.0
292 stars 29 forks source link

Ready event correctly fires #39

Closed Ortovoxx closed 3 years ago

Ortovoxx commented 3 years ago

The ready event will now fire when all shards are ready

timotejroiko commented 3 years ago

should emit Events.CLIENT_READY, not ShardEvents.READY, no?

Anyway no need to overcomplicate it. This should work:

this.on(Discord.Constants.Events.SHARD_RESUME, () => {
    if(!this.readyAt) { this.ws.checkShardReady(); }
})
Ortovoxx commented 3 years ago

Yes you're right it should be CLIENT_READY it doesn't make much of a difference because both constants are "ready" and so it emits the same event but I will add it in for completeness

Not quite sure what you mean with checkShardReady ? That method doesn't seem to exist?

The reason I added the extra logic is to only emit the ready event once all shards were ready not just the first one.

timotejroiko commented 3 years ago

checkShardReady does exactly that

https://github.com/discordjs/discord.js/blob/master/src/client/websocket/WebSocketManager.js#L394

timotejroiko commented 3 years ago

also, its better to use Discord.Constants.Events rather than import Constants from discord.js to account for possible modifications done to Discord in classes.js

Ortovoxx commented 3 years ago

Noted. Added those changes. Couldn't find that method but seems to do exactly what I intended ahaha

Thanks