diff options
Diffstat (limited to 'cogs/music')
| -rw-r--r-- | cogs/music/play.py | 14 | ||||
| -rw-r--r-- | cogs/music/play_compressed.py | 11 |
2 files changed, 2 insertions, 23 deletions
diff --git a/cogs/music/play.py b/cogs/music/play.py index cf04ded..2314545 100644 --- a/cogs/music/play.py +++ b/cogs/music/play.py | |||
| @@ -1,6 +1,4 @@ | |||
| 1 | import asyncio | ||
| 2 | import logging | 1 | import logging |
| 3 | |||
| 4 | import discord | 2 | import discord |
| 5 | import yt_dlp | 3 | import yt_dlp |
| 6 | from discord.ext import commands | 4 | from discord.ext import commands |
| @@ -46,18 +44,8 @@ class Play(commands.Cog): | |||
| 46 | 'options': '-vn' | 44 | 'options': '-vn' |
| 47 | } | 45 | } |
| 48 | 46 | ||
| 49 | def after_playing(error): | ||
| 50 | if error: | ||
| 51 | logger.error(f'Player error: {error}') | ||
| 52 | coro = vc.disconnect() | ||
| 53 | fut = asyncio.run_coroutine_threadsafe(coro, self.bot.loop) | ||
| 54 | try: | ||
| 55 | fut.result() | ||
| 56 | except Exception as e: | ||
| 57 | logger.error(f'Error disconnecting: {e}', exc_info=True) | ||
| 58 | |||
| 59 | source = discord.FFmpegPCMAudio(url2, **ffmpeg_options) | 47 | source = discord.FFmpegPCMAudio(url2, **ffmpeg_options) |
| 60 | vc.play(source, after=after_playing) | 48 | vc.play(source) |
| 61 | await ctx.followup.send(f"gra: {title}") | 49 | await ctx.followup.send(f"gra: {title}") |
| 62 | logger.info(f"Playing: {title}") | 50 | logger.info(f"Playing: {title}") |
| 63 | except Exception as e: | 51 | except Exception as e: |
diff --git a/cogs/music/play_compressed.py b/cogs/music/play_compressed.py index dd8dfd8..2bae269 100644 --- a/cogs/music/play_compressed.py +++ b/cogs/music/play_compressed.py | |||
| @@ -89,19 +89,10 @@ class GrajcujZkompresowane(commands.Cog): | |||
| 89 | found_file = compressed_file_path | 89 | found_file = compressed_file_path |
| 90 | found_title = title | 90 | found_title = title |
| 91 | title = found_title | 91 | title = found_title |
| 92 | def after_playing(error): | ||
| 93 | if error: | ||
| 94 | logger.error(f'Player error: {error}') | ||
| 95 | coro = vc.disconnect() | ||
| 96 | fut = asyncio.run_coroutine_threadsafe(coro, self.bot.loop) | ||
| 97 | try: | ||
| 98 | fut.result() | ||
| 99 | except Exception as e: | ||
| 100 | logger.error(f'Error disconnecting: {e}', exc_info=True) | ||
| 101 | 92 | ||
| 102 | if vc.is_playing() or vc.is_paused(): | 93 | if vc.is_playing() or vc.is_paused(): |
| 103 | vc.stop() | 94 | vc.stop() |
| 104 | vc.play(discord.FFmpegPCMAudio(found_file), after=after_playing) | 95 | vc.play(discord.FFmpegPCMAudio(found_file)) |
| 105 | await ctx.followup.send(f"gra (zkompresowane): {title}") | 96 | await ctx.followup.send(f"gra (zkompresowane): {title}") |
| 106 | logger.info(f"Playing audio: {title}") | 97 | logger.info(f"Playing audio: {title}") |
| 107 | 98 | ||
