python - Discord bot无法连接到语音通道(python)
问题描述
我想在 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
如果有人有想法,非常感谢
解决方案
您需要安装 PyNaCl 库,您可以使用 pip 获取该库:https ://pypi.org/project/PyNaCl/
推荐阅读
- python - 如何在水平曲线图中添加更多水平?
- javascript - express 验证器:分离逻辑
- hibernate - com.ibm.websphere.ce.cm.ConnectionWaitTimeoutException:CWTE_NORMAL_J2CA1009
- python - 在 tensorflow 图执行期间访问训练数据
- mysql - 从 myISAM 转换为 INNODB 的表正在减慢查询速度
- azure - Powershell Pester 输出和 PublishTestResults@2 任务“找不到要发布的结果”
- mean - 多模态:集中趋势和分散
- string - Golang 中的字符串和字符
- c++ - 唯一随机数检查表单数组c ++
- angular - '承诺
' 不可分配给类型 'Contact[]'