AttributeError:“FFmpegPCMAudio”对象没有属性“_process”

Posted

技术标签:

【中文标题】AttributeError:“FFmpegPCMAudio”对象没有属性“_process”【英文标题】:AttributeError: 'FFmpegPCMAudio' object has no attribute '_process' 【发布时间】:2021-11-11 15:41:21 【问题描述】:

我正在尝试制作一个不和谐的音乐机器人,这是我的播放功能:

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' 但是那里的解决方案并没有解决我的问题。

【问题讨论】:

【参考方案1】:

FFMPEG_OPTIONS 对象中,它应该是'options': '-vn' 而不是'option':'-vn'

【讨论】:

哦,哇,这一直是一个小错字。非常感谢。 没问题,很高兴能帮上忙。

以上是关于AttributeError:“FFmpegPCMAudio”对象没有属性“_process”的主要内容,如果未能解决你的问题,请参考以下文章

AttributeError:“字节”对象没有属性“告诉”

AttributeError: 'RDD' 对象没有属性 'show'

AttributeError:“NumpyArrayIterator”对象没有属性“类”

AttributeError:模块 'dbus' 没有属性 'lowlevel'

AttributeError:模块'keras'没有属性'initializers'

AttributeError:“会话”对象没有属性“会话”