【问题标题】:RuntimeError: PyNaCl library needed in order to use voiceRuntimeError:使用语音需要 PyNaCl 库
【发布时间】:2020-09-12 10:13:16
【问题描述】:
Traceback (most recent call last):
  File "C:\Users\Pradeep Tejwani\AppData\Local\Programs\Python\Python38\lib\site-packages\discord\ext\commands\bot.py", line 892, in invoke
    await ctx.command.invoke(ctx)
  File "C:\Users\Pradeep Tejwani\AppData\Local\Programs\Python\Python38\lib\site-packages\discord\ext\commands\core.py", line 797, in invoke
    await injected(*ctx.args, **ctx.kwargs)
  File "C:\Users\Pradeep Tejwani\AppData\Local\Programs\Python\Python38\lib\site-packages\discord\ext\commands\core.py", line 92, 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

这是我的错误,即使我同时安装了 python 库 pynacldiscord.py[voice]。我尝试了很多次,但仍然出现同样的错误。我什至将我的库更新到了较新的版本,但没有任何改变。

代码:

@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 voice.disconnect()

    if voice and voice.is_connected():
        await voice.move_to(channel)
    else:
        voice = await channel.connect()
        print(f"The bot has connected to {channel}\n")

    await ctx.send(f"Joined {channel}")

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

    if voice and voice.is_connected():
        await voice.disconnect()
        print(f"The bot has left {channel}")
        await ctx.send(f"Left {channel}")
    else:
        print("Bot was told to leave voice channel, but was not in one")
        await ctx.send("Don't think I am in a voice channel")

【问题讨论】:

  • 你确定你运行脚本的解释器与你使用 pip 安装包时使用的解释器相同吗?
  • 我使用vs code(虚拟工作室代码)运行脚本和cmd提示安装包
  • 从两个终端(CMD 和 VScode)运行命令 where python 并确保它们指向同一个地方
  • 当我在 vs 代码中运行 Python 时,我什么也得不到
  • 好的,等一下,我在 cmd 和 vs 代码中的结果是一样的

标签: python discord.py-rewrite


【解决方案1】:

你安装了 PyNaCl 吗? 如果没有,请从PyPi 下载 PyNaCl 或者安装discord.py的Voice Version 或者在你的控制台输入这个

python3 -m pip install -U discord.py[语音]

还有一点注意事项:Discord.py 现在是 1.5.1 版(我不知道你是否是最新的),PyNaCl 现在是 >1.4.0 版

【讨论】:

  • 我确实安装了 pynacl
  • @NishitaTejwani 也就是说,下载discord.py的Voice Versionpython3 -m pip install -U discord.py[voice]
  • 我确实安装了所有东西
  • @NishitaTejwani 尝试输入pip list 并查找PyNaCl,或者 Tyr 以管理员身份运行控制台,然后尝试再次安装。
  • 我遇到了同样的问题,一切正常,直到几周前它突然告诉我我没有 pynacl,就像我安装的其他人一样。
【解决方案2】:

您必须安装 PyNaCl 才能正常工作!您可以在终端中尝试pip install PyNaClpip3 install PyNaCl, 或者您可以尝试在代码顶部粘贴以下 sn-p:

import os, platform
try:
    import nacl
except ImportError:
    try:
        if platform.system().lower().startswith('win'):
            os.system("pip install pynacl")
        else:
            os.system("pip3 install pynacl")
    except Exception as e:
        print("Error:", e)
        exit()

如果缺少此代码将下载它!

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-08-02
    • 2020-02-06
    • 2018-02-23
    • 1970-01-01
    • 1970-01-01
    • 2020-03-22
    • 1970-01-01
    相关资源
    最近更新 更多