使机器人加入VC并播放音乐

时间:2018-12-26 19:15:30

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

我的代码使bot加入了vc,但它不播放音乐,而且bot出现以下错误,我不理解,我真的需要帮助来修复错误:(

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

1 个答案:

答案 0 :(得分:0)

PyNaCl library needed in order to use voice

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

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

进行安装。