Receiving error 'Cannot destroy VoiceConnection - it has already been destroyed'

Hi there, I've made a bot that essentially grabs mp3 files from a folder and plays them in a voice channel. It can do this perfectly, only issue, if the command is activated several times in a short span of time, it gives me the error, 'Cannot destroy VoiceConnection - it has already been destroyed' and I'm not sure why. Is there a way to catch this error that I'm not understanding or just prevent it in general through changing code or adding a cooldown? Thanks!
14 Replies
d.js docs
d.js docs3y ago
• What's your exact discord.js npm list discord.js and node node -v version? • Post the full error stack trace, not just the top part! • Show your code! • Explain what exactly your issue is. • Not a discord.js issue? Check out #useful-servers.
Matte
Matte3y ago
you're trying to destroy a connection that is already destroyed
WreckNoFear
WreckNoFearOP3y ago
Yes I get that much but don't see where
Matte
Matte3y ago
you should add logs around your code and find where the error is thrown
WreckNoFear
WreckNoFearOP3y ago
fair enough ill give that a try Ah gotcha. Where would I go about catching the error assuming that's the easiest option Right makes sense just to ensure I'm doing it right, which something tells me I'm not, would this be adequate: player.on(AudioPlayerStatus.Idle, () => connection.destroy().catch(error => console.log(error))); Strange then I'm getting Cannot read properties of undefined (reading 'catch') So in that case, catching the error wouldn't be the best method.
WreckNoFear
WreckNoFearOP3y ago
All good, I've changed it and it's still giving me the same error
WreckNoFear
WreckNoFearOP3y ago
This time the error came up a few seconds after the bot disconnected Hm. Hasn't crashed, didn't think to check that part for some unknown reason Ah yes, although now, it's decided to crash with 'Cannot play a resource that has already ended.' This time it has indeed crashed It appears to occur after I select one resource to play, then immediately play another.
WreckNoFear
WreckNoFearOP3y ago
I should mention that the files being played are controlled by interaction buttons (as below)
WreckNoFear
WreckNoFearOP3y ago
so if I were to increase the delay Yeah that didn't do much. Any other ideas? Thanks for your help so far I'm sure I'm just not getting it lol How would I go about unregistering the event listener? Not quite sure how...
WreckNoFear
WreckNoFearOP3y ago
so something along the lines of that?
WreckNoFear
WreckNoFearOP3y ago
Sorry I am really lost.
WreckNoFear
WreckNoFearOP3y ago
That's what I've gotten. I know there's something wrong though. I'm really sorry to bother you
WreckNoFear
WreckNoFearOP3y ago
WreckNoFear
WreckNoFearOP3y ago
Still erroring with this, maybe I still haven't done something right here Alright mate, thanks for your help, I'll have to work this out somehow. Gotta go but thank you!
Want results from more Discord servers?
Add your server