【问题标题】:Making a bot join a vc and play music让机器人加入 vc 并播放音乐
【发布时间】:2019-05-24 23:03:27
【问题描述】:

我的代码使机器人加入了 vc,但它不播放音乐,而且机器人给出了以下错误,我不明白,我真的需要帮助修复错误:(

Ignoring exception in command play
Traceback (most recent call last):
  File "C:\Users\Owner\AppData\Local\Programs\Python\Python36-32\lib\site-packages\discord\ext\commands\core.py", line 50, in wrapped
    ret = yield from coro(*args, **kwargs)
  File "C:\Users\Owner\Desktop\cool boi\coolboi.py", line 184, in play
    vc = await bot.join_voice_channel(voice_channel)
  File "C:\Users\Owner\AppData\Local\Programs\Python\Python36-32\lib\site-packages\discord\client.py", line 3209, in join_voice_channel
    voice = VoiceClient(**kwargs)
  File "C:\Users\Owner\AppData\Local\Programs\Python\Python36-32\lib\site-packages\discord\voice_client.py", line 217, 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\Owner\AppData\Local\Programs\Python\Python36-32\lib\site-packages\discord\ext\commands\bot.py", line 846, in process_commands
    yield from command.invoke(ctx)
  File "C:\Users\Owner\AppData\Local\Programs\Python\Python36-32\lib\site-packages\discord\ext\commands\core.py", line 374, in invoke
    yield from injected(*ctx.args, **ctx.kwargs)
  File "C:\Users\Owner\AppData\Local\Programs\Python\Python36-32\lib\site-packages\discord\ext\commands\core.py", line 54, in wrapped
    raise CommandInvokeError(e) from e
discord.ext.commands.errors.CommandInvokeError: Command raised an exception: RuntimeError: PyNaCl library needed in order to use voice

代码是

@bot.command(pass_context=True)
async def play(ctx):
    url = ctx.message.content
    url = url.strip('???? play ')

    author = ctx.message.author
    voice_channel = author.voice_channel
    vc = await bot.join_voice_channel(voice_channel)

    player = await vc.create_ytdl_player(url)
    player.start()

【问题讨论】:

  • 可能你应该安装 PyNaCl。到目前为止,您关于 discord bot 的问题 - install 请求了一个库,以(在回溯的最后一行中查找名称)

标签: python python-3.x discord discord.py


【解决方案1】:
PyNaCl library needed in order to use voice

您需要安装 PyNaCl 库才能使用语音功能。运行

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

安装它。

【讨论】:

  • 好吧,他周围是绿色的,但他没有发出声音,但这可能是我的错XD
  • 如果你只是 pip install discord.py 它不会安装 PyNaCl,(因为它是一个很大的依赖项)。运行上面的命令来安装语音特定的依赖项(在某些系统上,这个命令只是pip install -U discord.py[voice],你可能需要稍微尝试一下。
猜你喜欢
  • 2021-11-03
  • 2021-05-05
  • 1970-01-01
  • 2021-10-01
  • 2022-01-04
  • 2021-08-15
  • 2019-12-12
  • 2022-01-21
  • 2021-10-25
相关资源
最近更新 更多