我无法将Discord Python BOT连接到语音通道,为什么?

时间:2020-08-13 13:55:55

标签: python discord bots pynacl

我试图将我的BOT连接到语音通道以进行音乐BOT,但是我不知道为什么,它不起作用。你能帮我吗 ?我已经安装了PyNaCl,但仍然无法正常工作...

这是命令的代码:

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

这是显示的错误:

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

我真的需要帮助,但没有找到答案...

2 个答案:

答案 0 :(得分:0)

如果您使用的是像Pycharm这样的IDE,则应尝试将PyNaCl手动添加到项目解释器中

为什么不使用ctx.author.voice.channel.connect()将漫游器连接到用户当前的语音通道?

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

我的完整音乐https://github.com/Voz-bonita/Discord-Bot/blob/master/Music%20extension.py

答案 1 :(得分:0)

好的,我找到了怎么办。我需要打开cmd,然后键入py -3 -m pip install pynacl,仅此而已。 以前,我看到了许多其他与此类似的命令,但这是正确的命令。