我为我的不和谐机器人发出命令,在youtube上播放视频中的声音。这个功能很好,如果你打电话给她一次,但第二次我得到错误,我的机器人已经连接到这个语音通道。 所以我试图在他播放视频后断开机器人,但它没有用。
功能:
@bot.command(pass_context=True)
async def video(ctx, msg):
author = ctx.message.author
voice_channel = author.voice_channel
vc = await bot.join_voice_channel(voice_channel)
player = await vc.create_ytdl_player(url)
player.start()
await vc.disconnect() #not good, the video not playing
没有await vc.disconnect()
的错误:
yield from injected(*ctx.args, **ctx.kwargs)
File "/usr/local/lib/python3.6/dist-packages/discord/ext/commands/core.py", line 54, in wrapped
raise CommandInvokeError(e) from e
discord.ext.commands.errors.CommandInvokeError: Command raised an exception: ClientException: Already connected to a voice channel in this server
感谢帮助者^^度过了愉快的一天!
答案 0 :(得分:0)
你应该看看how danny does it in the examples。否则,checking if the bot is already connected to a servers voice channel可以解决您的问题,而player.start()
可以解决问题,因为这不会阻止stream player完成播放,此时您将断开与语音频道的连接流就好了。