Random shard sessionInfo errors

Hello, I have recently started getting an error when trying to start my bot. The error seems to be coming from DiscordJS directly, I have not written this code.
C:\Users\nikki\Documents\Code\discord_bots\discord-bot\node_modules\discord.js\src\client\websocket\WebSocketManager.js:268
if (shard.sessionInfo) {
^

TypeError: Cannot read properties of undefined (reading 'sessionInfo')
at WebSocketManager.<anonymous> (C:\Users\nikki\Documents\Code\discord_bots\discord-bot\node_modules\discord.js\src\client\websocket\WebSocketManager.js:268:17)
at WebSocketManager.emit (C:\Users\nikki\Documents\Code\discord_bots\discord-bot\node_modules\@vladfrangu\async_event_emitter\src\index.ts:360:28)
at WebSocketShard.<anonymous> (C:\Users\nikki\Documents\Code\discord_bots\discord-bot\node_modules\@discordjs\ws\src\strategies\sharding\SimpleShardingStrategy.ts:32:47)
at WebSocketShard.emit (C:\Users\nikki\Documents\Code\discord_bots\discord-bot\node_modules\@vladfrangu\async_event_emitter\src\index.ts:371:33)
at WebSocketShard.onMessage (C:\Users\nikki\Documents\Code\discord_bots\discord-bot\node_modules\@discordjs\ws\src\ws\WebSocketShard.ts:755:10)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
C:\Users\nikki\Documents\Code\discord_bots\discord-bot\node_modules\discord.js\src\client\websocket\WebSocketManager.js:268
if (shard.sessionInfo) {
^

TypeError: Cannot read properties of undefined (reading 'sessionInfo')
at WebSocketManager.<anonymous> (C:\Users\nikki\Documents\Code\discord_bots\discord-bot\node_modules\discord.js\src\client\websocket\WebSocketManager.js:268:17)
at WebSocketManager.emit (C:\Users\nikki\Documents\Code\discord_bots\discord-bot\node_modules\@vladfrangu\async_event_emitter\src\index.ts:360:28)
at WebSocketShard.<anonymous> (C:\Users\nikki\Documents\Code\discord_bots\discord-bot\node_modules\@discordjs\ws\src\strategies\sharding\SimpleShardingStrategy.ts:32:47)
at WebSocketShard.emit (C:\Users\nikki\Documents\Code\discord_bots\discord-bot\node_modules\@vladfrangu\async_event_emitter\src\index.ts:371:33)
at WebSocketShard.onMessage (C:\Users\nikki\Documents\Code\discord_bots\discord-bot\node_modules\@discordjs\ws\src\ws\WebSocketShard.ts:755:10)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
It also happens on my bot host/vps and I changed no code, it just started happening. I have tried switching my DiscordJS version to the latest, the dev and others but the error persists. If you want to take a look at the source code, it is all here: https://github.com/CuteNikki/discord-bot/ (also ik discord-player is against tos, pls don't mention it)
10 Replies
d.js toolkit
d.js toolkitโ€ข4mo 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
Nikki ๐ŸŒบ
Nikki ๐ŸŒบOPโ€ข4mo ago
:nyaDed: I'm not violating anything, I'm not even using it, it's just there I can remove it rn if that makes you happy also I'm pretty sure it's okay if you only use soundcloud with it Yeah, I copied it over a while ago 3h ago? Where are you getting that from The git commit for it is 2 months ago and the code for it was written much earlier than that anyways, that's not what I created this forum post for I updated the file 3 days ago but only to the SlashcommandBuilder
Nikki ๐ŸŒบ
Nikki ๐ŸŒบOPโ€ข4mo ago
there you go
No description
Nikki ๐ŸŒบ
Nikki ๐ŸŒบOPโ€ข4mo ago
oops I didn't remove the ffmpeg part from the setup part in the readme The issue seems to be gone again now My bot is starting fine The issue is only happening on my host with the exact same code atm locally it works Yeah, I also deleted the node modules folder locally and on the host and reinstalled everything so idk it's definitely an issue that exists in the latest as well as the dev version
Nikki ๐ŸŒบ
Nikki ๐ŸŒบOPโ€ข4mo ago
this is what some more clever people (from the sharding package I use) said
No description
Nikki ๐ŸŒบ
Nikki ๐ŸŒบOPโ€ข4mo ago
No, it also did the same when I started the bot without the ShardingManager but right now it's working again locally and on the host Yeah, chrissy said two different things and put an OR between them he was just assuming what could have gone wrong there I don't think they logged anything, just told me to do that but I was unable to at the time
Nikki ๐ŸŒบ
Nikki ๐ŸŒบOPโ€ข4mo ago
The problem here is definitely that shard is being accessed even though it could be undefined
No description
Nikki ๐ŸŒบ
Nikki ๐ŸŒบOPโ€ข4mo ago
Odd that I got the same error without using the third party sharding manager then I can't log anything while it's fine right now, I can do that if it happens again though I'm just very confused by the inconsistency of this issue sometimes it works and sometimes it doesn't I can't reproduce it, just showed up a few times yesterday and then it doesn't work for a while. But when it happened I commented out anything related to the Sharding Manager in my client class and started the bot file directly (not the sharding manager file) and got the same error again it just goes away after waiting for maybe around 20-30 minutes I said that commenting it out didnโ€™t work either I still get the same error, it doesnโ€™t matter if i use the sharding manager or not No, i did not receive that error I was running a dev bot thatโ€™s only in one guild
Nikki ๐ŸŒบ
Nikki ๐ŸŒบOPโ€ข4mo ago
@Qjuh It seems to happen again and the console log shows that the shardId is undefined
No description
Nikki ๐ŸŒบ
Nikki ๐ŸŒบOPโ€ข4mo ago
Running the bot without any kind of sharding results in the exact same error (just want to add that this is also no issue with bun, I tried others) Printing this.shards results in this:
<ref *1> Collection(1) [Map] {
0 => WebSocketShard {
_events: [Object: null prototype] { allReady: [Function (anonymous)] },
_eventsCount: 1,
_maxListeners: undefined,
manager: WebSocketManager {
_events: [Object: null prototype] {},
_eventsCount: 0,
_maxListeners: undefined,
gateway: 'wss://gateway.discord.gg/',
shards: [Circular *1],
status: 3,
destroyed: false,
_ws: [WebSocketManager],
totalShards: 1,
[Symbol(shapeMode)]: false,
[Symbol(kCapture)]: false
},
id: 0,
status: 1,
closeSequence: 0,
ping: -1,
lastPingTimestamp: -1,
[Symbol(shapeMode)]: false,
[Symbol(kCapture)]: false
}
}
<ref *1> Collection(1) [Map] {
0 => WebSocketShard {
_events: [Object: null prototype] { allReady: [Function (anonymous)] },
_eventsCount: 1,
_maxListeners: undefined,
manager: WebSocketManager {
_events: [Object: null prototype] {},
_eventsCount: 0,
_maxListeners: undefined,
gateway: 'wss://gateway.discord.gg/',
shards: [Circular *1],
status: 3,
destroyed: false,
_ws: [WebSocketManager],
totalShards: 1,
[Symbol(shapeMode)]: false,
[Symbol(kCapture)]: false
},
id: 0,
status: 1,
closeSequence: 0,
ping: -1,
lastPingTimestamp: -1,
[Symbol(shapeMode)]: false,
[Symbol(kCapture)]: false
}
}
I also added the warn and debug events to see if there might be an issue with discord but the only thing it logs is this:
[22:07:23.422] DEBUG (25788): Provided token: ** censored **
[22:07:23.423] DEBUG (25788): Preparing to connect to the gateway...
[22:07:23.650] DEBUG (25788): [WS => Manager] Fetched Gateway Information
URL: wss://gateway.discord.gg
Recommended Shards: 1
[22:07:23.650] DEBUG (25788): [WS => Manager] Session Limit Information
Total: 1000
Remaining: 996
[22:07:23.651] DEBUG (25788): [WS => Manager]
[22:07:23.652] DEBUG (25788): [WS => Manager]
[22:07:23.422] DEBUG (25788): Provided token: ** censored **
[22:07:23.423] DEBUG (25788): Preparing to connect to the gateway...
[22:07:23.650] DEBUG (25788): [WS => Manager] Fetched Gateway Information
URL: wss://gateway.discord.gg
Recommended Shards: 1
[22:07:23.650] DEBUG (25788): [WS => Manager] Session Limit Information
Total: 1000
Remaining: 996
[22:07:23.651] DEBUG (25788): [WS => Manager]
[22:07:23.652] DEBUG (25788): [WS => Manager]
and then the error right after that.. I also want to add that this is the third device that I have run this code on and gotten the exact same issue I just cloned the repo as is, installed the packages and then tried multiple ways to start the bot I'll go ahead and mark this as solved because of what didinele said on the github issue:
Yes, we merged a pull request into /ws that changes how we do events entirely. What you're experiencing here is discord.js not being updated to handle that (on purpose at this time), there isn't actually a bug.

Feel free to re-open if you can reproduce without the dev version of ws being used.
Yes, we merged a pull request into /ws that changes how we do events entirely. What you're experiencing here is discord.js not being updated to handle that (on purpose at this time), there isn't actually a bug.

Feel free to re-open if you can reproduce without the dev version of ws being used.
so if anyone comes across this error, just remove the "@discordjs/ws": "dev" override in your package.json
Want results from more Discord servers?
Add your server