From 706f4a31dff0eeab67220aaa3719773a96b54342 Mon Sep 17 00:00:00 2001 From: Logan Cusano Date: Sun, 27 Feb 2022 18:40:36 -0500 Subject: [PATCH] Working on bug in leaving --- bot.py | 8 ++++---- sound.py | 6 ++++++ 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/bot.py b/bot.py index 0b0f114..136b02e 100644 --- a/bot.py +++ b/bot.py @@ -93,7 +93,7 @@ class Bot(commands.Bot): # Create an audio stream from selected device self.streamHandler = sound.PCMStream(self.DEVICE_ID) # Start the audio stream - self.streamHandler.stream.start() + self.streamHandler.play() # Play the stream voice_connection.play(discord.PCMAudio(self.streamHandler)) @@ -119,12 +119,12 @@ class Bot(commands.Bot): async def leave(ctx, member: discord.Member = None): member = member or ctx.author.display_name if self.Bot_Connected: - print("Cleaning up") - # Stop the sound handlers - self.streamHandler.clean_up() print("Disconnecting") # Disconnect the client from the voice channel await ctx.voice_client.disconnect() + print("Cleaning up") + # Stop the sound handlers + self.streamHandler.pause() print("Changing presence") # Change the presence to away and '@ me' await self.set_activity(False) diff --git a/sound.py b/sound.py index 2d02fc4..8d48f0b 100644 --- a/sound.py +++ b/sound.py @@ -26,6 +26,12 @@ class PCMStream: self.stream.stop(ignore_errors=True) self.stream.close(ignore_errors=True) + def pause(self): + self.stream.stop(ignore_errors=True) + + def play(self): + self.stream.start() + def read(self, num_bytes): if self.stream.active: # frame is 4 bytes