AttributeError: 'FFmpegPCMAudio' object has no attribute '_process'
AttributeError: 'FFmpegPCMAudio' object has no attribute '_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'
我发现了一个相关的 post 有类似的错误:AttributeError: 'FFmpegPCMAudio' object has no attribute 'start'
但是那里的解决方案并没有解决我的问题。
在 FFMPEG_OPTIONS
对象中,它应该是 'options': '-vn'
而不是 'option':'-vn'
。
我正在尝试制作一个不和谐的音乐机器人,这是我的播放功能:
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'
我发现了一个相关的 post 有类似的错误:AttributeError: 'FFmpegPCMAudio' object has no attribute 'start' 但是那里的解决方案并没有解决我的问题。
在 FFMPEG_OPTIONS
对象中,它应该是 'options': '-vn'
而不是 'option':'-vn'
。