Bot crashing when a user leaves then joins any voice channel on server while bot is playing a audio file.
Error:
C:\Users\USER\Desktop\BotBot\indev\node_modules\discord.js\lib\Client\InternalClient.js:2088
if (connection.voiceChannel.id !== data.channel_id) {
^
TypeError: Cannot read property 'id' of null
at WebSocket.websocket.onmessage (C:\Users\USER\Desktop\BotBot\indev\node_modules\discord.js\lib\Client\InternalClient.js:2088:34)
at WebSocket.onMessage (C:\Users\USER\Desktop\BotBot\indev\node_modules\ws\lib\WebSocket.js:418:14)
at emitTwo (events.js:105:20)
at WebSocket.emit (events.js:185:7)
at Receiver.ontext (C:\Users\USER\Desktop\BotBot\indev\node_modules\ws\lib\WebSocket.js:816:10)
at C:\Users\USER\Desktop\BotBot\indev\node_modules\ws\lib\Receiver.js:477:18
at Receiver.applyExtensions (C:\Users\USER\Desktop\BotBot\indev\node_modules\ws\lib\Receiver.js:364:5)
at C:\Users\USER\Desktop\BotBot\indev\node_modules\ws\lib\Receiver.js:466:14
at Receiver.flush (C:\Users\USER\Desktop\BotBot\indev\node_modules\ws\lib\Receiver.js:340:3)
at Receiver.opcodes.1.finish (C:\Users\USER\Desktop\BotBot\indev\node_modules\ws\lib\Receiver.js:482:12)
My Code
var discord = require('discord.js');
var bot = new discord.Client();
bot.login(EMAIL, PASSWORD);
bot.on('message', function(message) {
if (message.content === "play") {
bot.joinVoiceChannel(message.author.voiceChannel, function() {
bot.voiceConnection.playFile(__dirname+'/test.mp3', {
volume: 0.75
}, function(error, intent) {
intent.on('end', function() {
bot.leaveVoiceChannel();
});
})
})
}
});
Found where the bug triggered. Seems like an attempt to create "voiceMoved" Event which is not documented in the docs. This move event is useless because its triggered on voiceJoin and voiceLeave.
When I remove this block of code it fixes the bug.
InternalClient.js (Lines: 2086 - 2093)
if (connection) {
// existing connection, perhaps channel moved
if (connection.voiceChannel.id !== data.channel_id) {
// moved, update info
connection.voiceChannel = self.channels.get("id", data.channel_id);
client.emit("voiceMoved", connection.voiceChannel); // Moved to a new channel
}
}
/tableflip
may you pleeeeassseeeeeeeeeeeeee fix this bug? thanks!
bugs are liferino :100:
Bug has been fixed
This bug still occurred for me (since I'm using OAuth, while this example doesn't)
Made a pull request that fixes the issue:
Most helpful comment
/tableflip