From 2becc408198f296dfa6508bd51089310299bafa7 Mon Sep 17 00:00:00 2001 From: Wizzard Date: Tue, 6 Feb 2024 00:17:15 -0500 Subject: [PATCH] Change livestream logic --- commands/livestream.js | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/commands/livestream.js b/commands/livestream.js index b7838ca..473bef4 100644 --- a/commands/livestream.js +++ b/commands/livestream.js @@ -5,14 +5,19 @@ module.exports = { description: 'Starts or stops a live stream in a voice channel with a provided video link.', async execute(message, args, deleteTimeout) { if (args[0] === 'stop') { - const voiceState = message.guild.members.me.voice; - if (voiceState.channel) { - voiceState.disconnect(); - return message.channel.send('Livestream stopped.') - .then(msg => setTimeout(() => msg.delete().catch(console.error), deleteTimeout)); + if (message.client.voiceConnection) { + message.client.voiceConnection.disconnect(); + message.client.voiceConnection = null; + + if (message.client.currentPlayer) { + message.client.currentPlayer.stop(); + message.client.currentPlayer.removeAllListeners('end'); + message.client.currentPlayer = null; + } + + return message.channel.send('Livestream stopped.').then(msg => setTimeout(() => msg.delete().catch(console.error), deleteTimeout)); } else { - return message.channel.send('No active livestream to stop.') - .then(msg => setTimeout(() => msg.delete().catch(console.error), deleteTimeout)); + return message.channel.send('No active livestream to stop.').then(msg => setTimeout(() => msg.delete().catch(console.error), deleteTimeout)); } }