Getting- Cannot destroy VoiceConnection - it has already been destroyed
Hi there, I asked for help with this yesterday and it was unresolved, still having the same issue. I did some digging and can't work out what's going on here. I have a bot that plays sound bytes from mp3 files locally stored, when I select the byte to play via interaction buttons, it plays. Sometimes if they are constantly selected or selected too quickly, it displays the error in the title of this post. Any solutions? Thanks!
50 Replies
• 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.Check if the connection is destroyed before attempting to destroy it
how would I go about doing that?
gotcha.
How can I check for this?
Nah, not this sorry
But you need to check if the connection state is destroyed
how would I check that though?
VoiceConnection#state
And you can equal to this enumI understand that, but I'm not sure how to program that in.
Not entirely sure. Will do next time
Just an if statement
<VoiceConnection>.state === <VoiceConnectionState>
Archive one of themsomething like this?
Its an enum...
Enuns are like objects
yeah thats what I'm not getting...
Use the intenlissense on VoiceConnectionStates
Like
VoiceConnectionState.
and see what vscode shows as valid properties
Enums are a more redable way to define possible values for somethingIf I quite literally type
VoiceConnectionStates.
it does not Intelisense anything..Did you import them from @discordjs/voice?
I've imported
VoiceConnectionStates VoiceConnection
Ow, my bad on something
When we wrap something on <> it means the class that should be substituted for the equivalent on your code, in your case your
VoiceConnection
is called connection
ah right, that makes sense
And
VoiceConnectionState
should have the Destroyed
property
Its without the sI think you mean
VoiceConnectionStatus
?State not states
because that has
Destroyed
propertyThat can be
VoiceConnectionState
doesn't appear to existBut is is called state
That's what I've got
Lol, bug
It must be
If it works, nice
compared with that
Its Status if I'm not wrong, I was reading the source
ah right
just one last thing
this is what I've got. It's definately not crashing now if I were to spam the sound byte buttons, although it's not leaving on idle now
Two thinks
yea?
And you need to compare
<VoiceConnection>.state.status
For some reason its very confusingAlright I've done that and now I've managed to lock it into an infinite join then leave loop
I have realised why though I think
It joins the channel, then leaves
I think its because its initially idled, if im not wrong
Can be
Is there a way I can get around that?
You can try to add this event inside of the playing event of player
Actually
Try setting it inside the setTimeout
Setting the if statement in a setTimeout?
or the player.on event?
No, the event listener for the Idle
gotcha
This
Yeah but now it'll only run once
Nvm I retract that statement
@jpbm135 You've actually managed to solve my issue im so thankful
Works perfectly! Thank you so much