Sharded Discord.js bot resets to initial presence status

I wrote a Discord.js bot in NodeJS that uses discord-hybrid-sharding to spawn my bot.js. In the bot.js code below, you can see that I have an initial status of "Starting..." and then in ClientReady I set the actual status. However, seemingly at random, my bot just goes back to the initial "Starting..." status. It operates completely normally though. I assumed it could be that a shard died or something, but why would that kill my interval? The check I tried to do in the Interval sadly doesn't work. Full question with code on stackoverflow, no answer so far sadly: https://stackoverflow.com/q/79047421/7575111
NodeJS v20.11.1
NodeJS v20.11.1
No description
5 Replies
d.js toolkit
d.js toolkit3mo ago
- 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 OP
NyR
NyR3mo ago
That's because you set the "Starting.." status in your client options, so if there is any reconnects, it falls back to what is set on the ClientOptions, now this would work as you intended if your setPresence in the interaval actually gets called evrytime (essentially setting a new presence), but that only happens when the guild count changes, which I imagine doesn't happen that often. So you get the above said behavior Also no need to shard with only 200 guilds..
Shadow
ShadowOP2mo ago
is there a way to catch reconnect events? so I can set the correct status again? also, I feel like it still kills my interval. because it used to be 5 minutes and in my if condition for the guild count I also had || status == "Starting..." but that didn't fix it sadly just checked, its still in the code
const statusHasReset = client.user?.presence.activities[0].name === "Starting...";
if (newGuildCount !== lastGuildCount || statusHasReset){
const statusHasReset = client.user?.presence.activities[0].name === "Starting...";
if (newGuildCount !== lastGuildCount || statusHasReset){
so it shouldn't only set when the guild count changes the hybrid sharding package does it automatically on-demand, but currently it only starts one shard I'd rather have it now instead of having it too late. there is no disadvantage in using it already anyway, even if it just spawns one single shard. but this is besides the point of this question anyway. even if I remove sharding now and the problem is "resolved", once I implement it again, the problem will be back. so why not find an answer now rather than later? What do you mean "nothing we can do about it"? I never said that it's a bug in Discord.js or something. But this is a Q&A forum and the question is about DiscordJS features
Amgelo
Amgelo2mo ago
this is a server for djs support, if it's not an issue with djs itself there's nothing djs can do
Shadow
ShadowOP2mo ago
Thank you so so much! Moving the setInterval logic to shardReady did the trick!
Want results from more Discord servers?
Add your server