0

I've tried to connect my BOT to a voice channel to do a music BOT, but I don't know why, it doesn't work. Can you help me please ? I've already install PyNaCl, and it still doesn't working...

This is the code of the command :

@bot.command()
async def join(ctx):
    channel = get(ctx.guild.voice_channels, id=722012728176410694)
    await channel.connect()

And here is the error that is printed :

Ignoring exception in command join:
Traceback (most recent call last):
  File "C:\Users\Maxence\AppData\Local\Programs\Python\Python37-32\lib\site-packages\discord\ext\commands\core.py", line 83, in wrapped
    ret = await coro(*args, **kwargs)
  File "C:\Users\Maxence\Documents\Programmation\Python\Discord\Music BOT\main.py", line 44, in join
    await channel.connect()
  File "C:\Users\Maxence\AppData\Local\Programs\Python\Python37-32\lib\site-packages\discord\abc.py", line 1076, in connect
    voice = VoiceClient(state=state, timeout=timeout, channel=self)
  File "C:\Users\Maxence\AppData\Local\Programs\Python\Python37-32\lib\site-packages\discord\voice_client.py", line 91, 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 "C:\Users\Maxence\AppData\Local\Programs\Python\Python37-32\lib\site-packages\discord\ext\commands\bot.py", line 892, in invoke
    await ctx.command.invoke(ctx)
  File "C:\Users\Maxence\AppData\Local\Programs\Python\Python37-32\lib\site-packages\discord\ext\commands\core.py", line 797, in invoke
    await injected(*ctx.args, **ctx.kwargs)
  File "C:\Users\Maxence\AppData\Local\Programs\Python\Python37-32\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

I really need help I found no answers...

Ecen
  • 1
  • 1
  • if you add `import nacl` at the top of `main.py`, the import works (as in no ImportError raised)? – dh762 Aug 13 '20 at 14:01
  • also check other questions... https://stackoverflow.com/questions/53936196/making-a-bot-join-a-vc-and-play-music#comment94713735_53936579 – dh762 Aug 13 '20 at 14:05
  • @dh762 When I do `import nacl` at the top, it put me another error, but no `ImportError` : `aiohttp.client_exceptions.ClientConnectorCertificateError: Cannot connect to host discordapp.com:443 ssl:True [SSLCertVerificationError: (1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: certificate has expired (_ssl.c:1123)')]` – Ecen Aug 14 '20 at 12:37

2 Answers2

0

If you are using an IDE like Pycharm you should try to add PyNaCl mannualy to the project interpreter

Why dont you use the ctx.author.voice.channel.connect() to connect the bot to the user's current voice channel?

 @commands.command()
 async def entrar(ctx):
    canal = ctx.author.voice.channel
    #I suggest make it global so other commands can acess it
    global voice_client
    voice_client = await canal.connect()

My full music cog https://github.com/Voz-bonita/Discord-Bot/blob/master/Music%20extension.py

Voz bonita
  • 360
  • 2
  • 10
  • I am using Sublime Text 3, and yes I will do the `ctx.author.voice.channel`, it is better thanks – Ecen Aug 14 '20 at 12:39
  • By copy/paste your code, it give the same error, so it's not my code... – Ecen Aug 14 '20 at 13:26
0

OK I found how to do. I need to open the cmd, then type py -3 -m pip install pynacl and that's all. Before, I saw many other commands that's seems to this, but this one is the correct one.

Ecen
  • 1
  • 1