connection destroy, disconnect

Is it possible to destroy the connection with disconnecting the bot, I’ve a command that play an audio < 35 sec What I’m doing right now that i just use the same connection, but then i will see the warn
13 Replies
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
! Alk
! AlkOP2y ago
v13
duck
duck2y ago
you haven't shown any code and your question is a little vague but from what I gather, you're calling <VoiceConnection>.disconnect() then later connecting with joinVoiceChannel and adding one or more event listeners to the connection, resulting in listeners piling up due to the VoiceConnection being reused is that correct?
! Alk
! AlkOP2y ago
if (!connection) connection = joinVC(interaction.member.voice.channel)
let player = connection.state.subscription.player;

connection.subscribe(player);
const resource = createAudioResource(item.path);
player.play(resource)


connection.on('stateChange', (oldState, newState) => {
const oldNetworking = Reflect.get(oldState, 'networking');
const newNetworking = Reflect.get(newState, 'networking');

const networkStateChangeHandler = (oldNetworkState, newNetworkState) => {
const newUdp = Reflect.get(newNetworkState, 'udp');
clearInterval(newUdp?.keepAliveInterval);
}

oldNetworking?.off('stateChange', networkStateChangeHandler);
newNetworking?.on('stateChange', networkStateChangeHandler);
});

connection.on(VoiceConnectionStatus.Disconnected, async (oldState, newState) => {
try {
if (connection && connection.state.status != "destroyed") {
console.log("Vdestroyed")
connection.destroy();
connection.disconnect();
};
} catch (er) {
console.log("VdesconnEr. " + er)
}
});
if (!connection) connection = joinVC(interaction.member.voice.channel)
let player = connection.state.subscription.player;

connection.subscribe(player);
const resource = createAudioResource(item.path);
player.play(resource)


connection.on('stateChange', (oldState, newState) => {
const oldNetworking = Reflect.get(oldState, 'networking');
const newNetworking = Reflect.get(newState, 'networking');

const networkStateChangeHandler = (oldNetworkState, newNetworkState) => {
const newUdp = Reflect.get(newNetworkState, 'udp');
clearInterval(newUdp?.keepAliveInterval);
}

oldNetworking?.off('stateChange', networkStateChangeHandler);
newNetworking?.on('stateChange', networkStateChangeHandler);
});

connection.on(VoiceConnectionStatus.Disconnected, async (oldState, newState) => {
try {
if (connection && connection.state.status != "destroyed") {
console.log("Vdestroyed")
connection.destroy();
connection.disconnect();
};
} catch (er) {
console.log("VdesconnEr. " + er)
}
});
i want the bot to stay in the channel and destroy the connection to prevent this warn
duck
duck2y ago
if you destroy the connection, the bot will disconnect there is no way to destroy the connection without disconnecting but this appears to be the patchwork fix for the recent voice issue
! Alk
! AlkOP2y ago
<a:4kr_think:971221604195524728>
duck
duck2y ago
which has been solved in the recent release of /voice 0.15.0
! Alk
! AlkOP2y ago
do u mean i need to update to prevent this warn?
duck
duck2y ago
the warning has nothing to do with the keepalive issue as you can read in the warning, there are just too many listeners being added to the same event emitter this code from what I can tell is the patchwork fix for said keepalive issue, but with the issue being solved, you could remove it entirely after updating
! Alk
! AlkOP2y ago
! Alk
! AlkOP2y ago
or just remove this
duck
duck2y ago
you could remove it entirely after updating
! Alk
! AlkOP2y ago
yeah i will try now ty working perfectly just like you
Want results from more Discord servers?
Add your server