diff --git a/bot.py b/bot.py index 136b02e..728e099 100644 --- a/bot.py +++ b/bot.py @@ -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("Disconnecting") - # Disconnect the client from the voice channel - await ctx.voice_client.disconnect() print("Cleaning up") # Stop the sound handlers self.streamHandler.pause() + print("Disconnecting") + # Disconnect the client from the voice channel + await ctx.voice_client.disconnect() print("Changing presence") # Change the presence to away and '@ me' await self.set_activity(False) diff --git a/sound.py b/sound.py index 8d48f0b..8be70b2 100644 --- a/sound.py +++ b/sound.py @@ -21,17 +21,23 @@ class PCMStream: self.stream = sd.RawInputStream(device=_device_id) + # Stops and destroys the current stream def clean_up(self): if not self.stream.closed: self.stream.stop(ignore_errors=True) self.stream.close(ignore_errors=True) + # Stops the current running stream but does not destroy it def pause(self): - self.stream.stop(ignore_errors=True) + if self.stream.active: + self.stream.stop(ignore_errors=True) + # Plays the stream def play(self): - self.stream.start() + if not self.stream.active: + self.stream.start() + # call back read function for the stream def read(self, num_bytes): if self.stream.active: # frame is 4 bytes