Discord.js: [6.1.0 indev] Crashing when user leaves then joins voice channel on server while playing audio file

Created on 8 Apr 2016  路  6Comments  路  Source: discordjs/discord.js

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();
                        });
                    })

            })
        }
});
bug

Most helpful comment

/tableflip

All 6 comments

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

Commit

This bug still occurred for me (since I'm using OAuth, while this example doesn't)

Made a pull request that fixes the issue:

266

Was this page helpful?
0 / 5 - 0 ratings

Related issues

BrandonCookeDev picture BrandonCookeDev  路  3Comments

iCrawl picture iCrawl  路  3Comments

Blumlaut picture Blumlaut  路  3Comments

Brawaru picture Brawaru  路  3Comments

DatMayo picture DatMayo  路  3Comments