【发布时间】:2021-10-10 17:03:33
【问题描述】:
歌曲结束后,歌曲会从播放列表队列中弹出,但不会继续播放队列中的下一首歌曲。所以队列命令只显示那里的歌曲。我应该如何更改它以运行下一首歌曲?
playlist = []
@client.command(name='play', help='Plays music')
async def play(ctx):
voice = ctx.message.guild.voice_client
def is_connected(): # Tests if bot is connected to voice channel
voice_client = discord.utils.get(ctx.bot.voice_clients, guild=ctx.guild)
return voice_client and voice_client.is_connected()
url = ctx.message.content.lstrip('?play')
playlist.append(url.lstrip(' '))
if not ctx.message.author.voice:
await ctx.send("You are not connected to a voice channel")
playlist.pop(0)
return
else:
channel = ctx.message.author.voice.channel
if is_connected():
if voice.is_playing(): # url already added to the playlist, downloads each index
index = len(playlist)-1
player = await YTDLSource.from_url(playlist[index], loop=client.loop)
await ctx.send('**Added:** {} to queue'.format(player.title))
playlist[index] = player.title
else:
server = ctx.message.guild
voice_channel = server.voice_client
async with ctx.typing():
player = await YTDLSource.from_url(playlist[0], loop=client.loop)
voice_channel.play(player, after=lambda e: print('Player error: %s' % e) if e else ctx.send('hi'))
print(player.title)
await ctx.send('**Now playing:** {}'.format(player.title))
playlist[0] = player.title
playlist.pop(0)
else:
await channel.connect()
server = ctx.message.guild
voice_channel = server.voice_client
async with ctx.typing():
player = await YTDLSource.from_url(playlist[0], loop=client.loop)
voice_channel.play(player, after=lambda e: print('Player error: %s' % e) if e else None)
print(player.title)
await ctx.send('**Now playing:** {}'.format(player.title))
playlist[0] = player.title```
【问题讨论】:
标签: python discord audio-player