python - 让机器人加入 vc 并播放音乐

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

我的代码使机器人加入 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 library needed in order to use voice

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

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

安装它。

关于python - 让机器人加入 vc 并播放音乐,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53936196/

相关文章:

javascript - 在 discord.js 中有什么方法可以像对待大写字符一样对待小写字符吗?

python - 如何在 Bokeh 中使用悬停工具提示显示整数而不是 float

python - 如何构建一个内存中的虚拟文件系统,然后将这个结构写入磁盘

python - 当我调用其他类中的方法时,出现 AttributeError

python - __init__ 括号里的东西叫什么?

javascript - 即使机器人离线或获得更新也能保存用户数据

javascript - 代码将自身循环三次并运行 "If"语句两次和 "Else"语句一次

python - 按组计算连续重复项

Python代码优化

Python 序数排序