【发布时间】:2020-09-01 23:05:03
【问题描述】:
我想知道是否有办法让我的不和谐机器人在播放 youtube 视频的音频后离开语音频道。我尝试使用sleep(duration of the video),但为了获取和下载要播放的视频,我使用了pafy,它给了我视频的持续时间,但格式为 00:00:00,它算作字符串,而不是整数。我将代码更改为在after=lamda e: await vc.disconnect 处断开连接,但它给了我一个错误提示'await' outside async function。我播放音乐的代码如下:
channel = message.author.voice.channel
vc = await channel.connect()
url = contents
url = url.strip("play ")
video = pafy.new(url)
await message.channel.send("Now playing **%s**" % video.title)
audio = video.getbestaudio()
audio.download()
duration = video.duration
player = vc.play(discord.FFmpegPCMAudio('%s.webm' % video.title), after=lambda e: await vc.disconnect)
【问题讨论】:
标签: python discord python-asyncio pafy