Bot Appearing Offline on Some Shards
I’m running a bot on 635K servers, using
discord-hybrid-sharding
and discord-cross-hosting
for efficient shard management. The setup works fine at the beginning, but after 6-7 hours of uptime, I experience the following issues:
1 Bot appears offline in some Discord servers (specific shards seem to stop functioning or disconnect).
2 .stats
command fails to return the correct total guilds and user count after 6-7 hours of operation.
I've been experiencing a problem My Bot Appearing Offline in some Discord servers (shards) despite all clusters being online and functioning normally. There are no shardDisconnect event calls, and everything seems to be connected correctly based on the logs.
I've consulted the discord-cross-hosting support server, and they mentioned it's unlikely to be a hybrid hosting issue, suggesting it might be related to Discord.js or a network problem. However, after troubleshooting this issue for the past 6-7 days and asking for help in multiple servers, I haven't found a solution.
The bot connects and resumes fine, with no disconnect events. All shards are sending heartbeat acknowledgements, but the bot is still shown as offline in certain servers.
Could an expert please help me debug this? I'm stuck and not sure what to do next. Any help would be greatly appreciated!25 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!Server.ts
index.ts
logs1
| [WS => Shard 124] Heartbeat acknowledged, latency of 107ms.
1 | [WS => Shard 265] Heartbeat acknowledged, latency of 105ms.
1 | [WS => Shard 125] Heartbeat acknowledged, latency of 111ms.
1 | [WS => Shard 267] Heartbeat acknowledged, latency of 115ms.
1 | [WS => Shard 19] Heartbeat acknowledged, latency of 105ms.
1 | [WS => Shard 300] Heartbeat acknowledged, latency of 106ms.
1 | [WS => Shard 117] Heartbeat acknowledged, latency of 107ms.
1 | [WS => Shard 118] Heartbeat acknowledged, latency of 111ms.
1 | [WS => Shard 133] Destroying shard
1 | Reason: Told to reconnect by Discord
1 | Code: 4200
1 | Recover: Resume
1 | [WS => Shard 133] Connection status during destroy
1 | Needs closing: true
1 | Ready state: 1
1 | [WS => Shard 202] Heartbeat acknowledged, latency of 106ms.
1 | [WS => Shard 233] Heartbeat acknowledged, latency of 112ms.
1 | [WS => Shard 150] Heartbeat acknowledged, latency of 105ms.
1 | [WS => Shard 133] Connecting to wss://gateway-us-east1-c.discord.gg?v=10&encoding=json
1 | [WS => Shard 133] Waiting for event hello for 60000ms
1 | [WS => Shard 133] Resuming session
1 | resume url: wss://gateway-us-east1-c.discord.gg
1 | sequence: 32204
1 | shard id: 133
1 | [WS => Shard 133] Resumed and replayed 5 events
Unknown User•2mo ago
Message Not Public
Sign In & Join Server To View
I've been using Discord.js as my main library
Unknown User•2mo ago
Message Not Public
Sign In & Join Server To View
i asked their support server, and they mentioned it's unlikely to be a hybrid hosting issue, suggesting it might be related to Discord.js or a network problem
Unknown User•2mo ago
Message Not Public
Sign In & Join Server To View
i'll do that now and try to reproduce the issue.
Unknown User•2mo ago
Message Not Public
Sign In & Join Server To View
Alright
i will tell them
about this
hi. I maintain most of the websocket code. I see people with situations like yours pop up every few months, and it's almost always someone using some 3rd party sharding solutions that we don't provide
quite frankly, I don't know what to tell you. the debug logs you provided imply everything is fine, shards don't simply disappear without any logs indicating they're about to disconnect, so-and-so
the maintainers of the packagers you're using are most likely, quite frankly, delusional :meguFace:
and while that may sound rude, no one has been able to show me to how to reproduce this "shard magically disappearing" stuff with just discord.js/
@discordjs/ws
Hybrid does nothing more than spawing a child process or worker process of your index.js after that you specify
shards
and shardCount
in the client construcutre its really just a process manager in order to cluster your bot based on internal sharding nothing more so a basic reproduction would be a ton of child processes with
shardCount: 8
shardIds: [0, 1, 2, 3, 4, 5, 6, 7]
and change the shardIds with the next pair if you want to try to reproduce it with djs/ws
The thing is this issue as you already said only comes some times every few months, myself I cannot reproduce that with a over 1300 shards bot nor with a 14 shards bot. Most users that have this issue ignore it until it just dosnt happen anymore.
side info which isnt that important
Hybird spawns a worker with
and a child process with
Hi! Let me know when you're actually reproduced it without hybrid & have associated debug logs. Thank you!
Make sure you don't have any code blocking processes. i.e. infinite cycles
I have this same issue where it shows an incorrect guild and user count after X hours of operation, without
discord-hybrid-sharding
though. Have you found a solution yet?if you get debug logs im sure the maintainer of ws will be happy to help (as above)
What would I even debug log?
I do not use a 3rd party sharding library and I have the same issue 😅
Or partly the same issue
literally the debug event
Event of what? I assumed it would be a shard event but it ain't, unless I'm not looking in the right place?
OOh just a client event... sorry me slow
:meguFace:
So what kind of debug looks would I be looking for whenever the issue occurs? If you have any idea
Alright I will get back whenever it occurs again :))
I didn't even know there was a "debug" event.. well I do now :theshrug:
So these are the debug logs from the time between it giving correct guild and member counts to now where it doesn't. I am not really sure what I would be looking for though https://codeshare.io/Ek0QNo
Before restart:
Server Count: 34,726
Member Count: 21,783
After restart:
Server Count: 34,697
Member Count: 1,367,868
:mdn: Promise.resolve()
The Promise.resolve() static method "resolves" a given value to a Promise. If the value is a promise, that promise is returned; if the value is a thenable, Promise.resolve() will call the then() method with two callbacks it prepared; otherwise the returned promise will be fulfilled with the value.
I had the same problem before using that. Someone else recommended it to me, although I don't remember where
You asked if it was a flaw in my code, so I sent the code. If I knew if there was a flaw, it wouldn't be there 😅
I do not think any shards go offline, as the total shards and
responsiveShards
are the same
But how could that be? It shows the correct counts but after X hours of running it doesn't. Exactly the same thing the OP said?This post is about two issues where I have one of them as well. They just titled it after the first issue
Ah yeah, now I get it, sorry 😅