Nishita Tejwani
Nishita Tejwani

Reputation: 21

RuntimeError: PyNaCl library needed in order to use voice

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

This is my error even though I have both the python libraries pynacl and discord.py[voice] installed. I tried it so many times but still got same error. I have even updated my library to newer versions but nothing changed.

Code:

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

Upvotes: 2

Views: 27176

Answers (2)

Hirusha Adikari
Hirusha Adikari

Reputation: 149

You have to install PyNaCl for this to work! You can try pip install PyNaCl or pip3 install PyNaCl in the terminal, or you can try pasting the below snippet at the top of you code:

import os
try:
    import nacl
except ImportError:
    try:
        if os.name == 'nt':
            os.system("py -m pip install pynacl")
        else:
            os.system("python3 -m install pynacl")
    except Exception as e:
        print("Error:", e)
        exit()

This code will download it if it is missing!

Upvotes: 1

Raphiel
Raphiel

Reputation: 388

have you installed PyNaCl? If you don't, download PyNaCl from PyPi Or Install the Voice Version of discord.py Or and type this to your console

python3 -m pip install -U discord.py[voice]

and a small Note : Discord.py is now version 1.5.1 (I Don't know if you're up to date) and PyNaCl is now version >1.4.0

Upvotes: 5

Related Questions