0

我试图将我的 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

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

4

2 回答 2

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

于 2020-08-13T14:18:02.223 回答
0

好的,我找到了该怎么做。我需要打开 cmd,然后输入py -3 -m pip install pynacl,仅此而已。之前,我看到了许多其他的命令,这似乎是,但这个是正确的。

于 2020-08-15T14:53:32.800 回答