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
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.
조아오
조아오3y ago
Check if the connection is destroyed before attempting to destroy it
WreckNoFear
WreckNoFearOP3y ago
how would I go about doing that? gotcha. How can I check for this?
d.js docs
d.js docs3y ago
property VoiceConnection#_state PRIVATE The state of the voice connection.
조아오
조아오3y ago
Nah, not this sorry But you need to check if the connection state is destroyed
WreckNoFear
WreckNoFearOP3y ago
how would I check that though?
조아오
조아오3y ago
VoiceConnection#state And you can equal to this enum
d.js docs
d.js docs3y ago
interface VoiceConnectionState The various states that a voice connection can be in.
WreckNoFear
WreckNoFearOP3y ago
I understand that, but I'm not sure how to program that in. Not entirely sure. Will do next time
조아오
조아오3y ago
Just an if statement <VoiceConnection>.state === <VoiceConnectionState> Archive one of them
WreckNoFear
WreckNoFearOP3y ago
something like this?
조아오
조아오3y ago
Its an enum... Enuns are like objects
WreckNoFear
WreckNoFearOP3y ago
yeah thats what I'm not getting...
조아오
조아오3y ago
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 something
WreckNoFear
WreckNoFearOP3y ago
If I quite literally type VoiceConnectionStates. it does not Intelisense anything..
조아오
조아오3y ago
Did you import them from @discordjs/voice?
WreckNoFear
WreckNoFearOP3y ago
I've imported VoiceConnectionStates VoiceConnection
조아오
조아오3y ago
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
WreckNoFear
WreckNoFearOP3y ago
ah right, that makes sense
조아오
조아오3y ago
And VoiceConnectionState should have the Destroyed property Its without the s
WreckNoFear
WreckNoFearOP3y ago
I think you mean VoiceConnectionStatus?
조아오
조아오3y ago
State not states
WreckNoFear
WreckNoFearOP3y ago
because that has Destroyed property
조아오
조아오3y ago
That can be
WreckNoFear
WreckNoFearOP3y ago
VoiceConnectionState doesn't appear to exist
조아오
조아오3y ago
But is is called state
WreckNoFear
WreckNoFearOP3y ago
That's what I've got
조아오
조아오3y ago
Lol, bug
WreckNoFear
WreckNoFearOP3y ago
It must be
조아오
조아오3y ago
If it works, nice
WreckNoFear
WreckNoFearOP3y ago
compared with that
조아오
조아오3y ago
Its Status if I'm not wrong, I was reading the source
WreckNoFear
WreckNoFearOP3y ago
ah right just one last thing
WreckNoFear
WreckNoFearOP3y ago
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
조아오
조아오3y ago
Two thinks
WreckNoFear
WreckNoFearOP3y ago
yea?
d.js docs
d.js docs3y ago
Checking for things to not be equal in JavaScript:
- if (!yourVariable === yourOtherVariable) // !yourVariable is coerced to a boolean value
+ if (yourVariable !== yourOtherVariable) // checks that one is not equal to the other
- if (!yourVariable === yourOtherVariable) // !yourVariable is coerced to a boolean value
+ if (yourVariable !== yourOtherVariable) // checks that one is not equal to the other
• Comparison operators in JavaScript: learn more
조아오
조아오3y ago
And you need to compare <VoiceConnection>.state.status For some reason its very confusing
WreckNoFear
WreckNoFearOP3y ago
Alright 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
WreckNoFear
WreckNoFearOP3y ago
It joins the channel, then leaves
WreckNoFear
WreckNoFearOP3y ago
I think its because its initially idled, if im not wrong
조아오
조아오3y ago
Can be
WreckNoFear
WreckNoFearOP3y ago
Is there a way I can get around that?
조아오
조아오3y ago
You can try to add this event inside of the playing event of player Actually Try setting it inside the setTimeout
WreckNoFear
WreckNoFearOP3y ago
Setting the if statement in a setTimeout? or the player.on event?
조아오
조아오3y ago
No, the event listener for the Idle
WreckNoFear
WreckNoFearOP3y ago
gotcha
조아오
조아오3y ago
This
WreckNoFear
WreckNoFearOP3y ago
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
조아오
조아오3y ago
dogeHaHa
Want results from more Discord servers?
Add your server