Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

voiceChannel.leave() : TypeError: Cannot read property 'leave' of null #20

Open
astariul opened this issue May 29, 2021 · 3 comments
Open
Labels
bug Something isn't working

Comments

@astariul
Copy link

When leaving a channel, I'm meeting the following error :

C:\Users\remon\Documents\workspace\discord-voice-recorder\bin\commands.js:48
voiceChannel.leave();
^

TypeError: Cannot read property 'leave' of null
at Object.exports.exit (C:\Users\remon\Documents\workspace\discord-voice-recorder\bin\commands.js:48:18)
at Client. (C:\Users\remon\Documents\workspace\discord-voice-recorder\index.js:22:51)
at Client.emit (events.js:376:20)
at MessageCreateAction.handle (C:\Users\remon\Documents\workspace\discord-voice-recorder\node_modules\discord.js\src\client\actions\MessageCreate.js:31:14)
at Object.module.exports [as MESSAGE_CREATE] (C:\Users\remon\Documents\workspace\discord-voice-recorder\node_modules\discord.js\src\client\websocket\handlers\MESSAGE_CREATE.js:4:32)
at WebSocketManager.handlePacket (C:\Users\remon\Documents\workspace\discord-voice-recorder\node_modules\discord.js\src\client\websocket\WebSocketManager.js:345:31)
at WebSocketShard.onPacket (C:\Users\remon\Documents\workspace\discord-voice-recorder\node_modules\discord.js\src\client\websocket\WebSocketShard.js:443:22)
at WebSocketShard.onMessage (C:\Users\remon\Documents\workspace\discord-voice-recorder\node_modules\discord.js\src\client\websocket\WebSocketShard.js:300:10)
at WebSocket.onMessage (C:\Users\remon\Documents\workspace\discord-voice-recorder\node_modules\ws\lib\event-target.js:132:16)
at WebSocket.emit (events.js:376:20)

Any idea where it comes from and how to fix it ?

@astariul
Copy link
Author

astariul commented May 29, 2021

Note : it happens only when the use leave the channel first.

When the user stay in the channel and send the command, it work properly.

To reproduce :

-> Cmd "enter"
-> Connect to discord voice channel
-> Say something
-> Disconnect from voice channel
-> Cmd "exit"

@astariul
Copy link
Author

Ok I changed :

const { channel: voiceChannel, connection: conn } = msg.guild.voiceStates.cache.last();

into

    var { channel: voiceChannel, connection: conn } = msg.guild.voiceStates.cache.last();
    if (voiceChannel == null){
        var { channel: voiceChannel, connection: conn } = msg.guild.voiceStates.cache.first();
    }

and it seems to work. I don't know enough javascript to find the actual solution, but this dirty work-around is fine for my usage.

@chebro chebro added the bug Something isn't working label Jun 6, 2021
@astariul
Copy link
Author

Turned out my fix does not work all the time...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants