【发布时间】:2021-03-21 16:12:51
【问题描述】:
我有这段代码,它可以在语音频道中播放歌曲并且工作正常,但是如何生成允许排队、暂停和循环的代码?
@client.command(pass_context=True)
async def play(ctx, url):
if not ctx.message.author.voice:
await ctx.send('Please enter the voice channel')
return
else:
channel = ctx.message.author.voice.channel
voice_client = await channel.connect()
guild = ctx.message.guild
with youtube_dl.YoutubeDL(ydl_opts) as ydl:
file = ydl.extract_info(url, download=True)
path = str(file['title']) + "-" + str(file['id'] + ".mp3")
voice_client.play(discord.FFmpegPCMAudio(path), after=lambda x: endSong(guild, path))
voice_client.source = discord.PCMVolumeTransformer(voice_client.source, 1)
await ctx.send(f'**NOW MUSIC: **{url}')
while voice_client.is_playing():
await asyncio.sleep(1)
else:
await voice_client.disconnect()
print("Disconnected")
【问题讨论】:
标签: python discord.py