Refactor code with self._next()
This commit is contained in:
parent
94d018246c
commit
45244896c8
15
src/bot.py
15
src/bot.py
|
@ -54,6 +54,12 @@ class Music(commands.Cog):
|
||||||
# pylint: disable=no-member
|
# pylint: disable=no-member
|
||||||
self._handle_playback.cancel()
|
self._handle_playback.cancel()
|
||||||
|
|
||||||
|
def _next(self):
|
||||||
|
"""Trigger playback of next song."""
|
||||||
|
self._queue.task_done()
|
||||||
|
if self._queue_lock.locked():
|
||||||
|
self._queue_lock.release()
|
||||||
|
|
||||||
@tasks.loop()
|
@tasks.loop()
|
||||||
async def _handle_playback(self):
|
async def _handle_playback(self):
|
||||||
while True:
|
while True:
|
||||||
|
@ -64,16 +70,14 @@ class Music(commands.Cog):
|
||||||
# Bot is no longer in a voice channel.
|
# Bot is no longer in a voice channel.
|
||||||
# This could be the case because a stop command was issued.
|
# This could be the case because a stop command was issued.
|
||||||
# We will skip this (and possibly all remaining songs) in the queue
|
# We will skip this (and possibly all remaining songs) in the queue
|
||||||
self._queue.task_done()
|
self._next()
|
||||||
self._queue_lock.release()
|
|
||||||
continue
|
continue
|
||||||
audio = discord.FFmpegPCMAudio(song.audio_url, **self._ffmpeg_options)
|
audio = discord.FFmpegPCMAudio(song.audio_url, **self._ffmpeg_options)
|
||||||
|
|
||||||
def after(err):
|
def after(err):
|
||||||
if err:
|
if err:
|
||||||
print(f"Player error: {err}")
|
print(f"Player error: {err}")
|
||||||
self._queue.task_done()
|
self._next()
|
||||||
self._queue_lock.release()
|
|
||||||
ctx.voice_client.play(audio, after=after)
|
ctx.voice_client.play(audio, after=after)
|
||||||
embed = NowPlayingMessage(title=song.title, url=song.webpage_url)
|
embed = NowPlayingMessage(title=song.title, url=song.webpage_url)
|
||||||
await ctx.send(embed=embed)
|
await ctx.send(embed=embed)
|
||||||
|
@ -83,8 +87,7 @@ class Music(commands.Cog):
|
||||||
if ctx:
|
if ctx:
|
||||||
embed = ErrorMessage(str(err))
|
embed = ErrorMessage(str(err))
|
||||||
await ctx.send(embed=embed)
|
await ctx.send(embed=embed)
|
||||||
self._queue.task_done()
|
self._next()
|
||||||
self._queue_lock.release()
|
|
||||||
|
|
||||||
@_handle_playback.before_loop
|
@_handle_playback.before_loop
|
||||||
async def before_handle_playback(self):
|
async def before_handle_playback(self):
|
||||||
|
|
Loading…
Reference in New Issue