首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >RuntimeError:使用语音所需的PyNaCl库

RuntimeError:使用语音所需的PyNaCl库
EN

Stack Overflow用户
提问于 2020-09-12 18:13:17
回答 2查看 7.6K关注 0票数 1
代码语言:javascript
复制
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],这也是我的错误。我试了很多次,但还是得到了同样的错误。我甚至将我的库更新到了更新的版本,但没有任何变化。

代码:

代码语言:javascript
复制
@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")
EN

回答 2

Stack Overflow用户

发布于 2020-10-02 11:46:40

你安装PyNaCl了吗?如果未安装,请从PyPi下载PyNaCl或安装discord.py或的Voice Version,然后在控制台中键入以下内容

python3 -m pip install -U discord.pyvoice

注意: Discord.py现在是1.5.1版(我不知道您是否更新了),而PyNaCl现在是1.4.0以上的版本

票数 1
EN

Stack Overflow用户

发布于 2021-09-02 09:57:45

你必须安装PyNaCl才能正常工作!您可以在终端中尝试使用pip install PyNaClpip3 install PyNaCl,也可以尝试将以下代码片段粘贴到代码顶部:

代码语言:javascript
复制
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()

如果这段代码丢失了,它将被下载!

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/63859231

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档