diff --git a/bot.py b/bot.py index 57903f2..24e9e25 100644 --- a/bot.py +++ b/bot.py @@ -88,15 +88,15 @@ class Bot(commands.Bot): await ctx.send(f"Ok {str(member).capitalize()}, I'm joining {channel}") # Join the voice channel with the audio stream - self.voice_connection = await channel.connect() + voice_connection = await channel.connect() # Create an audio stream from selected device self.streamHandler = sound.PCMStream(self.DEVICE_ID) # Start the audio stream - self.streamHandler.play() + await self.streamHandler.play() # Play the stream - self.voice_connection.play(discord.PCMAudio(self.streamHandler)) + voice_connection.play(discord.PCMAudio(self.streamHandler)) # Start the SDR and begin playing to the audio stream self.start_sdr() @@ -121,20 +121,24 @@ class Bot(commands.Bot): if self.Bot_Connected: print("Cleaning up") # Stop the sound handlers - self.streamHandler.pause() + await self.streamHandler.pause() + print("Disconnecting") # Disconnect the client from the voice channel - #await ctx.voice_client.disconnect() - await self.voice_connection.disconnect() + await ctx.voice_client.disconnect() + print("Changing presence") # Change the presence to away and '@ me' await self.set_activity(False) + # Stop the SDR so it can cool off print("Stopping SDR") self.stop_sdr() + print("Unlocking the bot") # 'Unlock' the bot self.Bot_Connected = False + print("Sending Goodbye") await ctx.send(f"Goodbye {str(member).capitalize()}.") else: diff --git a/sound.py b/sound.py index 8be70b2..c33d97e 100644 --- a/sound.py +++ b/sound.py @@ -28,12 +28,12 @@ class PCMStream: self.stream.close(ignore_errors=True) # Stops the current running stream but does not destroy it - def pause(self): + async def pause(self): if self.stream.active: self.stream.stop(ignore_errors=True) # Plays the stream - def play(self): + async def play(self): if not self.stream.active: self.stream.start()