Reputation: 1
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...
Upvotes: 0
Views: 1274
Reputation: 1
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.
Upvotes: 0
Reputation: 380
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
Upvotes: 0