【发布时间】:2020-05-31 18:12:25
【问题描述】:
我一直在尝试发出队列命令。 这成功地将输入附加到 dict,例如 ['song1', 'song2']。 但是尝试播放下一首歌曲而不等待当前歌曲完成, 导致已经播放错误。
async def queue(ctx):
ctx.message.guild.name = []
await ctx.message.channel.send('**-start of queue-**')
await ctx.message.channel.send('**-type end when done-**')
def ch(m):
return m.author == ctx.message.author and m.channel == ctx.message.channel
while True:
song = await client.wait_for('message', check=ch, timeout=30)
song_str = str(song.content)
song_f = song_str.translate({ord(c): None for c in string.whitespace})
if song_f == 'end':
print(ctx.message.guild.name)
break
ctx.message.guild.name.append(song_str)
vc = ctx.message.guild.voice_client
for song in ctx.message.guild.name:
player = await YTDLSource.from_url(song, loop=client.loop)
print(song)
vc.play(player)
【问题讨论】:
-
我设法让它工作,但这不是一个真正的解决方案,我为歌曲的长度 + 20 执行 asyncio.sleep,所以它会一直休眠到歌曲结束,然后尝试播放下一个,但这可能会失败,如果下载时间超过 20 秒,这不是真正的解决方案!
标签: python-3.x discord.py youtube-dl