Discord 机器人无法连接到语音通道 (python)

Discord bot can't connected to voice channel (python)

嗨 我想在 python 中制作一个可以连接到语音通道的 discord 机器人。我的代码:

@client.command()
async def join(ctx):
  channel = ctx.author.voice
  if str(channel) == 'None':
    await ctx.channel.send(':x: You have to be in a voice channel to use this command. :x:')
  else:
    channel = ctx.author.voice.channel
    await channel.connect()

显示此错误

Ignoring exception in command join:
Traceback (most recent call last):
  File "/opt/virtualenvs/python3/lib/python3.8/site-packages/discord/ext/commands/core.py", line 85, in wrapped
    ret = await coro(*args, **kwargs)
  File "main.py", line 25, in join
    await channel.connect()
  File "/opt/virtualenvs/python3/lib/python3.8/site-packages/discord/abc.py", line 1150, in connect
    voice = cls(client, self)
  File "/opt/virtualenvs/python3/lib/python3.8/site-packages/discord/voice_client.py", line 199, in __init__
    raise RuntimeError("PyNaCl library needed in order to use voice")
RuntimeError: PyNaCl library needed in order to use voice

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/opt/virtualenvs/python3/lib/python3.8/site-packages/discord/ext/commands/bot.py", line 902, in invoke
    await ctx.command.invoke(ctx)
  File "/opt/virtualenvs/python3/lib/python3.8/site-packages/discord/ext/commands/core.py", line 864, in invoke
    await injected(*ctx.args, **ctx.kwargs)
  File "/opt/virtualenvs/python3/lib/python3.8/site-packages/discord/ext/commands/core.py", line 94, in wrapped
    raise CommandInvokeError(exc) from exc
discord.ext.commands.errors.CommandInvokeError: Command raised an exception: RuntimeError: PyNaCl library needed in order to use voice

如果有人有想法,非常感谢

您需要安装 PyNaCl 库,您可以使用 pip 获取它:https://pypi.org/project/PyNaCl/