Question about connection.on

When a voice connection is destroyed, does the connection.on method get destroyed as well? Because I don't want to overload the bot, and I want to create a new connection.on method when creating a new connection.
14 Replies
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
! Alk
! Alk2y ago
I just came to ask the same question How to delete the old one or how to create only one "connection.on()" for multiple or all connections
duck
duck2y ago
when a connection is destroyed, it will not be used again joinVoiceChannel will create a new VoiceConnection, a separate object it will not have the previous object's event listeners a connection will only be reused when it has not been destroyed, which is to say if it is still currently connected/connecting, or if <VoiceConnection>.disconnect() was used instead of <VoiceConnection>.destroy()
SirNuny
SirNunyOP2y ago
Does player.on work the same way as connection.on? (player = VoiceClient.createAudioPlayer())
duck
duck2y ago
they have different events, but if you're just asking whether they both accept (eventName, fn) for their params, then yes both ons are inherited from EventEmitter
d.js docs
d.js docs2y ago
node nodeEventTarget.on(type, listener[, options]) Node.js-specific alias for eventTarget.addListener().
duck
duck2y ago
close enough
SirNuny
SirNunyOP2y ago
I mean when you destroy a voice connection, does the player gets destroyed as well?
duck
duck2y ago
no, a player is not specific to a single voice connection and can be used by multiple connections so it wouldn't make sense for destroying a single connection to destroy its subscribed player as well
SirNuny
SirNunyOP2y ago
And is there a way to destroy a player?
duck
duck2y ago
not really, you'd just stop the current resource and unsubscribe any connections from it (connections are also unsubscribed when destroyed) a player doesn't really do anything when it doesn't have any connections or resources to handle
SirNuny
SirNunyOP2y ago
So then the player.on doesn't take any memory, right?
duck
duck2y ago
I mean it takes as much memory as it normally does which is not a lot but garbage collection will come for it as normal
SirNuny
SirNunyOP2y ago
Okay, thank you
Want results from more Discord servers?
Add your server