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 User16mo ago
Message Not Public
Sign In & Join Server To View
! Alk
! Alk16mo 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
duck16mo 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
SirNuny16mo ago
Does player.on work the same way as connection.on? (player = VoiceClient.createAudioPlayer())
duck
duck16mo 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 docs16mo ago
node nodeEventTarget.on(type, listener[, options]) Node.js-specific alias for eventTarget.addListener().
duck
duck16mo ago
close enough
SirNuny
SirNuny16mo ago
I mean when you destroy a voice connection, does the player gets destroyed as well?
duck
duck16mo 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
SirNuny16mo ago
And is there a way to destroy a player?
duck
duck16mo 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
SirNuny16mo ago
So then the player.on doesn't take any memory, right?
duck
duck16mo 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
SirNuny16mo ago
Okay, thank you