Add try/except
This commit is contained in:
parent
d363960426
commit
abe268391f
12
src/bot.py
12
src/bot.py
|
@ -9,7 +9,7 @@ from dotenv import load_dotenv
|
|||
import youtube_dl
|
||||
|
||||
from error import ErrorHandler
|
||||
from message import NowPlayingMessage, QueuedMessage
|
||||
from message import NowPlayingMessage, QueuedMessage, ErrorMessage
|
||||
|
||||
load_dotenv()
|
||||
|
||||
|
@ -57,6 +57,7 @@ class Music(commands.Cog):
|
|||
@tasks.loop()
|
||||
async def _handle_playback(self):
|
||||
while True:
|
||||
try:
|
||||
await self._queue_lock.acquire()
|
||||
ctx, song = await self._queue.get()
|
||||
audio = discord.FFmpegPCMAudio(song.audio_url, **self._ffmpeg_options)
|
||||
|
@ -67,9 +68,16 @@ class Music(commands.Cog):
|
|||
self._queue.task_done()
|
||||
self._queue_lock.release()
|
||||
ctx.voice_client.play(audio, after=after)
|
||||
|
||||
embed = NowPlayingMessage(title=song.title, url=song.webpage_url)
|
||||
await ctx.send(embed=embed)
|
||||
# pylint: disable=broad-except
|
||||
except Exception as err:
|
||||
print(f"Error during playback: {err}")
|
||||
if ctx:
|
||||
embed = ErrorMessage(str(err))
|
||||
await ctx.send(embed=embed)
|
||||
self._queue.task_done()
|
||||
self._queue_lock.release()
|
||||
|
||||
@_handle_playback.before_loop
|
||||
async def before_handle_playback(self):
|
||||
|
|
Loading…
Reference in New Issue