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•2y ago
Message Not Public
Sign In & Join Server To View
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 connectionswhen 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()
Does player.on work the same way as connection.on?
(player = VoiceClient.createAudioPlayer())
they have different events, but if you're just asking whether they both accept
(eventName, fn)
for their params, then yes
both on
s are inherited from EventEmitter
close enough
I mean when you destroy a voice connection, does the player gets destroyed as well?
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
And is there a way to destroy a player?
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 handleSo then the player.on doesn't take any memory, right?
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
Okay, thank you