【问题标题】:Bot can't connect to voice channel - discord.py rewriteBot 无法连接到语音通道 - discord.py 重写
【发布时间】:2020-12-06 12:26:37
【问题描述】:

我正在使用 discord.py 重写制作一个不和谐机器人,但最近遇到了一个问题。

我已发出加入用户语音频道的命令。问题是,当我在本地 PC 上运行它时,我的命令运行得非常好,但现在我试图在树莓派上运行它,它在连接到语音通道时失败。

我已尝试安装所有依赖项,但无法使其正常工作。 命令代码:

@bot.command()
async def join(ctx):
    channel = ctx.message.author.voice.channel
    voice = get(bot.voice_clients, guild=ctx.guild)

    if voice and voice.is_connected():
        await voice.move_to(channel)
    else:
        voice = await channel.connect()

    await ctx.send("I joined the channel!")

没有引发异常。

【问题讨论】:

  • 你的 pi 支持语音库吗?以及诸如pynacl之类的东西
  • 我该如何检查?安装时我没有收到任何错误。
  • 你能把它连接起来吗?
  • 不,我想这与树莓派有关,但我无法弄清楚。

标签: python discord discord.py discord.py-rewrite


【解决方案1】:

您使用错误的方式连接到语音通道。 尝试使用此代码。

它识别用户的位置并在该语音通道中连接。

   @bot.command(name='join', invoke_without_subcommand=True)
    async def join(ctx):
       destination = ctx.author.voice.channel
       if ctx.voice_state.voice:
         await ctx.voice_state.voice.move_to(destination)
         return
    
       ctx.voice_state.voice = await destination.connect()
       await ctx.send(f"Joined {ctx.author.voice.channel} Voice Channel")

【讨论】:

    猜你喜欢
    • 2020-02-19
    • 2021-04-29
    • 2022-01-05
    • 2021-08-05
    • 1970-01-01
    • 2017-07-31
    • 1970-01-01
    • 2021-04-10
    • 2019-08-02
    相关资源
    最近更新 更多