作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我想知道是否有办法让我的不和谐机器人在播放 YouTube 视频的音频后离开语音 channel 。我尝试使用 sleep(视频的持续时间)
,但为了获取和下载要播放的视频,我使用了 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)
最佳答案
这里有一种在歌曲播放完毕后断开连接的方法(删除 after=
)。
添加在vc.play()
之后
while vc.is_playing():
await sleep(1)
await vc.disconnect()
关于python - 有没有办法让我的不和谐机器人在播放完歌曲后断开与语音 channel 的连接?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61830803/
我是一名优秀的程序员,十分优秀!