mirror of
				https://github.com/jarulsamy/Plex-Bot.git
				synced 2024-08-19 15:01:55 +02:00 
			
		
		
		
	catching a few exceptions and handling them accordingly
This commit is contained in:
		| @@ -299,15 +299,25 @@ class Plex(commands.Cog): | ||||
|         audio_stream = FFmpegPCMAudio(track_url) | ||||
|  | ||||
|         while self.voice_channel and self.voice_channel.is_playing(): | ||||
|             bot_log.debug("waiting for track to finish") | ||||
|             await asyncio.sleep(2) | ||||
|         bot_log.debug("track finished")             | ||||
|  | ||||
|         self.voice_channel.play(audio_stream, after=self._toggle_next) | ||||
|         if self.voice_channel: | ||||
|             self.voice_channel.play(audio_stream, after=self._toggle_next) | ||||
|      | ||||
|             plex_log.debug("%s - URL: %s", self.current_track, track_url) | ||||
|      | ||||
|             embed, img = self._build_embed_track(self.current_track) | ||||
|             self.np_message_id = await self.ctx.send(embed=embed, file=img) | ||||
|  | ||||
|         plex_log.debug("%s - URL: %s", self.current_track, track_url) | ||||
|  | ||||
|         embed, img = self._build_embed_track(self.current_track) | ||||
|         self.np_message_id = await self.ctx.send(embed=embed, file=img) | ||||
|     async def _play_next(self): | ||||
|         try: | ||||
|             self.current_track = await self.play_queue.get() | ||||
|         except asyncio.exceptions.CancelledError: | ||||
|             bot_log.debug("failed to pop queue") | ||||
|  | ||||
|              | ||||
|     async def _audio_player_task(self): | ||||
|         """ | ||||
|         Coroutine to handle playback and queuing | ||||
| @@ -331,13 +341,14 @@ class Plex(commands.Cog): | ||||
|                 try: | ||||
|                     # Disconnect after 15 seconds idle | ||||
|                     async with timeout(15): | ||||
|                         self.current_track = await self.play_queue.get() | ||||
|                         await self._play_next() | ||||
|                 except asyncio.TimeoutError: | ||||
|                     bot_log("timeout - disconnecting") | ||||
|                     await self.voice_channel.disconnect() | ||||
|                     self.voice_channel = None | ||||
|  | ||||
|             if not self.current_track: | ||||
|                 self.current_track = await self.play_queue.get() | ||||
|                 await self._play_next() | ||||
|  | ||||
|             await self._play() | ||||
|             await self.play_next_event.wait() | ||||
| @@ -510,8 +521,11 @@ class Plex(commands.Cog): | ||||
|  | ||||
|         # Connect to voice if not already | ||||
|         if not self.voice_channel: | ||||
|             self.voice_channel = await ctx.author.voice.channel.connect() | ||||
|             bot_log.debug("Connected to vc.") | ||||
|             try: | ||||
|                 self.voice_channel = await ctx.author.voice.channel.connect() | ||||
|                 bot_log.debug("Connected to vc.") | ||||
|             except asyncio.exceptions.TimeoutError: | ||||
|                 bot_log.debug("Cannot connect to vc - timeout")                 | ||||
|  | ||||
|     @command() | ||||
|     async def play(self, ctx, *args): | ||||
| @@ -548,7 +562,7 @@ class Plex(commands.Cog): | ||||
|             pass | ||||
|  | ||||
|         # Specific add to queue message | ||||
|         if self.voice_channel.is_playing(): | ||||
|         if self.voice_channel and self.voice_channel.is_playing(): | ||||
|             bot_log.debug("Added to queue - %s", title) | ||||
|             embed, img = self._build_embed_track(track, type_="queue") | ||||
|             await ctx.send(embed=embed, file=img) | ||||
|   | ||||
		Reference in New Issue
	
	Block a user