discord.js
discord.js copied to clipboard
joinVoiceChannel() fails with "TypeError: Cannot read properties of undefined (reading 'status')"
Which package is this bug report for?
voice
Issue description
Inconsistently, joinVoiceChannel() will throw error:
TypeError: Cannot read properties of undefined (reading 'status')
at Object.sendPayload
at createVoiceConnection
at joinVoiceChannel
Code sample
const guild = await discordClient.guilds.fetch(guildId);
const conn = joinVoiceChannel({
channelId: channelId,
guildId: guildId,
adapterCreator: guild.voiceAdapterCreator,
});
Package version
14.7.0
Node.js version
8.19.2
Operating system
macOS
Priority this issue should have
High
Which partials do you have configured?
No Partials
Which gateway intents are you subscribing to?
Guilds Guild_voice_states
Can you please provide the full stack trace (and never omit it)?
@Jiralite
The error is due to the WebSocketManager losing WebSocketShards. Guild.shard() then returns undefined. I was trying to run 25 shards on one machine so I believe my bot was underprovisioned.
I've since added a check in Guild. voiceAdapterCreator():
get voiceAdapterCreator() {
return methods => {
this.client.voice.adapters.set(this.id, methods);
return {
sendPayload: data => {
if (!this.shard) {
console.error("shard missing for guild", this.id);
return false;
}
if (this.shard.status !== Status.Ready) return false;
this.shard.send(data);
return true;
},
destroy: () => {
this.client.voice.adapters.delete(this.id);
},
};
};
}
Properly provisioning the bot has resolved the missing WebSocketShard issue, but I think emitting a more descriptive error could help a dev debug this issue much more quickly.
Thank you!
The WebSocket has been rewritten to a new implementation since this issue. Feel free to open a new issue if the problem persists with the new implementation (ideally on 14.11.0+).