discordjs / voice

Implementation of the Discord Voice API for discord.js and other JS/TS libraries
Apache License 2.0
328 stars 112 forks source link

Add checks for joinVoiceChannel (and similar functions) instead of silently crashing. #152

Closed ItzDerock closed 2 years ago

ItzDerock commented 3 years ago

Is your feature request related to a problem? Please describe. I spent over an hour trying to figure out why some code I updated to v13 wasn't working, and it turns out it was because VoiceState.channelID was removed from discord.js@dev. I had that passed into the channelId option in joinVoiceChannel. There was no error saying that the channel was null, instead my bot would disconnect from Discord and reconnect, and the only error that appears is that it didn't enter ready state in time. To find the error I had to enable debug messages on my Discord client and only then did I see Unknown opcode.. That still wasn't enough for me to figure it out and so I added a console.log to the payload variable defined in the createVoiceConnection function, and only after I saw that did I see that channel_id was undefined.

Describe the ideal solution Add some sort of error. Like "Expected string for channelId, but got undefined"

Describe alternatives you've considered An alternative would be to have everyone switch to typescript so this error doesn't go unnoticed, as their ide is going to scream at them and so is the typescript compiler.

Additional context nothing

amishshah commented 2 years ago

I understand the intentions behind this issue, but I really don't think it's the library's place to validate that it is being used correctly. If you get similar errors in future, I'd recommend debugging the variables that you're passing to the library and making sure they look correct. Also looking at documentation/typings to see what parameters and names are expected.