【问题标题】:discord music bot error, ClientException: Already connected to a voice channel in this server不和谐音乐机器人错误,ClientException:已连接到此服务器中的语音通道
【发布时间】:2018-09-07 03:01:57
【问题描述】:

我为我的 discord 机器人发出了一个命令,它会从 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

感谢帮助^^祝你有美好的一天!

【问题讨论】:

    标签: python bots discord


    【解决方案1】:

    你应该看看how danny does it in the examples。否则,您的问题可以通过checking if the bot is already connected to a servers voice channel 解决,并且第二次在您执行player.start() 后不会断开连接,因为这不会阻止stream player 完成播放,此时您会断开与语音通道的连接,并且流就会消失。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-05-23
      • 2021-11-21
      • 1970-01-01
      • 2019-04-04
      • 2021-11-03
      • 2020-06-20
      • 2019-02-26
      • 2018-08-24
      相关资源
      最近更新 更多