我想知道是否有办法让我的不和谐机器人在播放 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)