RuntimeError:需要PyNaCl库才能使用语音

时间:2020-09-12 10:13:16

标签: python discord.py-rewrite

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")

1 个答案:

答案 0 :(得分:0)

您安装了PyNaCl吗? 如果不这样做,请从PyPi下载PyNaCl 或安装discord.py的Voice Version 或者,然后在控制台上输入

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

还有一个小提示:Discord.py现在是1.5.1版(我不知道您是否是最新的),而PyNaCl现在是> 1.4.0版