Receiving "ShardingReadyTimeout" even though ready event is firing
Hi there! I'm dealing with a strange problem and I'm not sure how to handle it. I'm receiving a ShardingReadyTimeout error, but the ready event is being fired before the error is occuring, so I therefore not sure how to handle it. I'm pretty sure it's being caused by my event handler, but I'm not sure why or how. Essentially, when the bot is actually created, it's firing a
loadEvents
method which is loading all the event files within my event directory, and attaching them to the client object.
An event has a type of:
My index.ts, which is the sharding manager:
My client.ts, which is the actual bot code:
I'm extending the discord.js Client
object to support some of my own functionality, so here is that file:
8 Replies
- What's your exact discord.js
npm list discord.js
and node node -v
version?
- Not a discord.js issue? Check out #other-js-ts.
- Consider reading #how-to-get-help to improve your question!
- Explain what exactly your issue is.
- Post the full error stack trace, not just the top part!
- Show your code!
- Issue solved? Press the button!
- ā
Marked as resolved by OPI reached a character limit, so here's the rest of the info:
Here is my eventHandler class, which contains the loadEvents method:
The
loadFiles()
function is defined as
If I change the void loadEvents(CrystalClient.client)
line to a standard this.on("ready", () => { console.log("ready") })
method, it works. But when I'm loading events dynamically from an event file, it freaks out.
For reference, this event is being registered fine
But the error still fires
npm list discord.js && node -v
:
I know there's a lot there, I can break it down if needed but basically, ready event is being fired, but shard is still timing out and idk why
TL;DR
1) Sharding manager spawns a shard
2) The shard creates a client of type CrystalClient, which extends Client
3) The CrystalClient constructor calls the loadEvents method, which A) iterates over all files and filters the files by .js extensions and B) attaches them to the client object using client[event.once ? "once" : "on"](event.name, execute)
, where event.once
and execute
is a property on the imported Event
and execute
is defined as
The whole event loading process is completed after approx. 55.416ms according to the last run of my bot
4) One of those events that is loaded is the client's ready
event, which fires fine
5) However, after about 30 seconds the bot times out anyway
6) If void loadEvents()
is replaced with this.on("ready", () => { console.log("ready") })
within the constructor of CrystalClient
, no errors occur, leading me to believe it's something to do with the file loading process. However, again, the ready event is still being thrown as indicated by hardcoded console.log()
methods within the ready event file itselfdo you still have this issue if you don't remove all listeners from your client with
client.removeAllListeners()
in loadEvents
?Let me give that a shot, I'll report back in a sec
Hmm, oddly enough I don't, even after enabling all my bot's features again. Thinking through it, is that call removing the
ready
event from the client, therefore preventing it from being fired upon initial construction?Awesome, good to know. I'm assuming this method should be considered unsafe then and not used? At least, not during startup
I believe in general it's considered poor practice to remove listeners not set by the same section of code
but yes, especially in this case you'll specifically want to avoid indiscriminately removing all listeners
Alright, thank you very much. I'll figure out a way to only remove events created by me and not the client. Much appreciated!