Discord bot无法连接到语音通道(python)

Posted

技术标签:

【中文标题】Discord bot无法连接到语音通道(python)【英文标题】:Discord bot can't connected to voice channel (python) 【发布时间】:2021-04-29 16:44:54 【问题描述】:

Hy 我想在 python 中制作一个不和谐的机器人,可以连接到语音通道。我的代码:

@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

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

【问题讨论】:

【参考方案1】:

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

【讨论】:

谢谢。当我下载文件时,如何在代码中使用它? 当我使用 'pip install' 命令时,显示此错误: pip install C:\ProgramData\Discord\PyNaCl-1.4.0-cp38-cp38-win_amd64.whl WARNING: Requirement 'C :ProgramDataDiscordPyNaCl-1.4.0-cp38-cp38-win_amd64.whl' 看起来像一个文件名,但该文件不存在 错误:无效要求:'C:ProgramDataDiscordPyNaCl==1.4.0' 警告:您使用的是 pip 版本 20.2。 3;但是,版本 21.0 可用。您应该考虑通过“/opt/virtualenvs/python3/bin/python3 -m pip install --upgrade pip”命令进行升级。 有关如何使用 pip 的信息,请参阅 packaging.python.org/tutorials/installing-packages。确保 pip 可运行,然后运行命令pip install pynacl 它将自动抓取最新的源并安装。

以上是关于Discord bot无法连接到语音通道(python)的主要内容,如果未能解决你的问题,请参考以下文章

Discord bot python:discord.errors.ClientException:找不到ffmpeg

尝试通过语音通道播放 youtube 音频时 C# discord bot 未知操作码 8

Discord bot 正在运行,但无法连接到服务器

在 Discord 语音频道中播放 mp3 的最简单方法

如何访问discord.py中的哪个语音通道用户写入命令?

(Discord.py) 如何锁定和解锁语音通道