让机器人加入风投并播放音乐 [英] Making a bot join a vc and play music

查看:19
本文介绍了让机器人加入风投并播放音乐的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

Ignoring exception in command play
Traceback (most recent call last):
  File "C:UsersOwnerAppDataLocalProgramsPythonPython36-32libsite-packagesdiscordextcommandscore.py", line 50, in wrapped
    ret = yield from coro(*args, **kwargs)
  File "C:UsersOwnerDesktopcool boicoolboi.py", line 184, in play
    vc = await bot.join_voice_channel(voice_channel)
  File "C:UsersOwnerAppDataLocalProgramsPythonPython36-32libsite-packagesdiscordclient.py", line 3209, in join_voice_channel
    voice = VoiceClient(**kwargs)
  File "C:UsersOwnerAppDataLocalProgramsPythonPython36-32libsite-packagesdiscordvoice_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:UsersOwnerAppDataLocalProgramsPythonPython36-32libsite-packagesdiscordextcommandsot.py", line 846, in process_commands
    yield from command.invoke(ctx)
  File "C:UsersOwnerAppDataLocalProgramsPythonPython36-32libsite-packagesdiscordextcommandscore.py", line 374, in invoke
    yield from injected(*ctx.args, **ctx.kwargs)
  File "C:UsersOwnerAppDataLocalProgramsPythonPython36-32libsite-packagesdiscordextcommandscore.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]

以安装它。

这篇关于让机器人加入风投并播放音乐的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆