From 35f08b663ab3cd1d0a85c8fc1a2142c909a3e6aa Mon Sep 17 00:00:00 2001 From: Wizzard Date: Mon, 5 Feb 2024 23:42:20 -0500 Subject: [PATCH] If we get another .livestream command check if we're in a voice chat and disconnect and rejoin --- commands/livestream.js | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/commands/livestream.js b/commands/livestream.js index 29db3fa..b7838ca 100644 --- a/commands/livestream.js +++ b/commands/livestream.js @@ -5,7 +5,7 @@ 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.me.voice; + const voiceState = message.guild.members.me.voice; if (voiceState.channel) { voiceState.disconnect(); return message.channel.send('Livestream stopped.') @@ -30,6 +30,12 @@ module.exports = { .then(msg => setTimeout(() => msg.delete().catch(console.error), deleteTimeout)); } + const voiceState = message.guild.members.me.voice; + if (voiceState.channel) { + console.log('Already in a voice channel, leaving...'); + await voiceState.disconnect(); + } + try { if (message.client.currentPlayer) { message.client.currentPlayer.stop(); @@ -59,10 +65,10 @@ module.exports = { player.on('finish', () => { console.log('Media ended, replaying...'); - playStream(); + playStream(); }); - playStream(); + playStream(); message.channel.send('Livestream started with the provided video link.') .then(msg => setTimeout(() => msg.delete().catch(console.error), deleteTimeout));