python - Discord Bot 无法播放 YouTube 视频
问题描述
(顺便说一句,这是一个不和谐的机器人,我的代码运行完美,机器人可以加入语音频道,离开,但是当我要求它播放某些东西时,这就是问题所在。)我收到一个错误不要告诉我代码中的错误在哪里。我得到的错误是 [NULL @ 0x5596fd23d8e0] Unable to find a suitable output format for '5' 5: Invalid argument
这是我认为错误所在的代码部分。
@commands.command()
async def disconnect(self,ctx):
await ctx.voice_client.disconnect()
@commands.command()
async def play(self,ctx,url):
ctx.voice_client.stop()
FFMPEG_OPTIONS = {'before_options': '-reconnect_streamed 1'
'-reconnect_delay_max 5', 'options': '-vn'}
YDL_OPTIONS = {'format':"bestaudio"}
vc = ctx.voice_client
with youtube_dl.YoutubeDL(YDL_OPTIONS) as ydl:
info = ydl.extract_info(url, download=False)
url2 = info['formats'][0]['url']
source = await discord.FFmpegOpusAudio.from_probe(url2,
**FFMPEG_OPTIONS)
vc.play(source)
有没有人有任何想法?我在另一个线程上看到输出错误,但我不明白如何修复输出。
解决方案
推荐阅读
- signalr - 将 SignalR 聊天应用程序持久保存到数据库
- python - 如何使用 pandas 将 hhmmss.ff 格式转换为日期时间
- mongoose - Mongoose - 查找不在另一个对象列表中的对象
- mongodb - 在 Moongose 中排序后将 $lookup 结果限制为 1 个文档
- javascript - 将包含双引号的字符串从 node.js 脚本传递到 VBScript
- xml - 使用某个节点(Shell 脚本)shell 更新 XML 文件中的文本
- c# - C# Winforms - 不同控件具有相同属性名称的数据绑定
- c++ - 无法从 VRChaperone 访问游戏区
- templates - 使用 ansible 模板但 rysnc 移动文件
- r - 在 sparklyr 中使用 first、last、nth