AudioPlayer amd VoiceConnection life and listeners

If I destroy a voice connection that has an audioplayer subscribed, will the player also be garbage collected / destroyed? What about any event listeners attached to them? Do I need to remove them, or destroying the VoiceConnection removes them as well?
4 Replies
d.js toolkit
d.js toolkit•5mo ago
- What's your exact discord.js npm list discord.js and node node -v version? - Not a discord.js issue? Check out #other-js-ts. - Consider reading #how-to-get-help to improve your question! - Explain what exactly your issue is. - Post the full error stack trace, not just the top part! - Show your code! - Issue solved? Press the button!
Farleena (Dani)
Farleena (Dani)•5mo ago
What do you refer to by "no reference"?
Farleena (Dani)
Farleena (Dani)•5mo ago
Oh yeah right, I reread the guide and it is indeed there, sorry.
No description
Farleena (Dani)
Farleena (Dani)•5mo ago
Does declaring it as a constant like in the guide tho count as reference? const player = createAudioPlayer(); Thank you! So let's say I have two commands, one that connects the bot to a channel and plays something, and attaches some listeners to both the connection and the player to see their states. And the other disconnects the bot from voice. How would I ensure no garbage is left where it shouldn't be? I did this in the disconnect command:
getVoiceConnection(voiceChannel.guild.id).state.subscription.player.removeAllListeners().stop(true); getVoiceConnection(voiceChannel.guild.id).removeAllListeners().destroy();
getVoiceConnection(voiceChannel.guild.id).state.subscription.player.removeAllListeners().stop(true); getVoiceConnection(voiceChannel.guild.id).removeAllListeners().destroy();
is this valid? or I could actually store the connection in a const as it does have it's destroy method, only the player needs to be without references.. 🤔 ?