python - 让机器人加入 vc 并播放音乐
问题描述
我的代码使机器人加入了 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]
安装它。
推荐阅读
- html - 将值从一个表传递到另一个 html 页面
- c++ - 如何使用中值滤波算法去除胡椒噪声
- c++ - 在 if 语句中声明时如何访问类对象?(在 C++ 中)
- java - java - 如何在java swing中加载本地html文件?
- centos7 - Clearcase - 无法访问 VOB - ls:读取目录 - 权限被拒绝
- android - 如何在 viewpager 中使用 webview 的水平滚动?
- swift - 文本文件中的 Swift 转换格式(字符串解析)
- spring-boot - spring boot配置自定义sql
- c# - 如何获取列表框中所选项目的索引值?
- android - 使用 DownloadManager 下载视频文件时,应用程序在 Android 10 上崩溃