ffmpeg - AttributeError:“FFmpegPCMAudio”对象没有属性“_process”
问题描述
我正在尝试制作一个不和谐的音乐机器人,这是我的播放功能:
async def play(self, ctx, url):
ctx.voice_client.stop()
FFMPEG_OPTIONS = {'before_options': '-reconnect 1 -reconnect_streamed 1 -reconnect_delay_max 5', 'option': '-vn'}
YDL_OPTIONS = {'format': 'bestaudio'}
voice = ctx.voice_client
with youtube_dl.YoutubeDL(YDL_OPTIONS) as ydl:
info = ydl.extract_info(url, download=False)
url2 = info['formats'][0]['url']
voice.play(discord.FFmpegPCMAudio(url2, **FFMPEG_OPTIONS))
但是当我运行代码时,出现以下错误:
[youtube] MbhXIddT2YY: Downloading webpage
Exception ignored in: <function AudioSource.__del__ at 0x7f1fca7373a0>
Traceback (most recent call last):
File "/opt/virtualenvs/python3/lib/python3.8/site-packages/discord/player.py", line 103, in __del__
self.cleanup()
File "/opt/virtualenvs/python3/lib/python3.8/site-packages/discord/player.py", line 154, in cleanup
proc = self._process
AttributeError: 'FFmpegPCMAudio' object has no attribute '_process'
Ignoring exception in command play:
Traceback (most recent call last):
File "/opt/virtualenvs/python3/lib/python3.8/site-packages/discord/ext/commands/core.py", line 85, in wrapped
ret = await coro(*args, **kwargs)
File "/home/runner/Myoojic-Baat/music.py", line 42, in play
voice.play(discord.FFmpegPCMAudio(url2, **FFMPEG_OPTIONS))
TypeError: __init__() got an unexpected keyword argument 'option'
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/opt/virtualenvs/python3/lib/python3.8/site-packages/discord/ext/commands/bot.py", line 939, in invoke
await ctx.command.invoke(ctx)
File "/opt/virtualenvs/python3/lib/python3.8/site-packages/discord/ext/commands/core.py", line 863, in invoke
await injected(*ctx.args, **ctx.kwargs)
File "/opt/virtualenvs/python3/lib/python3.8/site-packages/discord/ext/commands/core.py", line 94, in wrapped
raise CommandInvokeError(exc) from exc
discord.ext.commands.errors.CommandInvokeError: Command raised an exception: TypeError: __init__() got an unexpected keyword argument 'option'
我发现了一个有类似错误的相关帖子:AttributeError: 'FFmpegPCMAudio' object has no attribute 'start' 但是那里的解决方案没有解决我的问题。
解决方案
在FFMPEG_OPTIONS
对象中它应该'options': '-vn'
不是'option':'-vn'
。
推荐阅读
- ios - 如何从 Swift 4 中的另一个类正确调用函数(其中包含 IBOutlet 变量)
- angularjs - How to filter the data on array and remove some data in angular
- c# - Unity 中有 MultiKeyDictionary 吗?
- python - 在 Python 中读取文件行时如何不创建无限循环?
- video - 修改FPS引起的异常
- java - 滚动视图顶部的静态按钮 android studio
- python - 如何使用变量列表循环函数?
- javascript - Javascript:函数前的 $ 是什么意思?
- php - Laravel hasmanythrough 或 mysql groupby
- regex - 使用 sed \t 时列未对齐