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

标签: ffmpegdiscorddiscord.pyaudio-playeryoutube-dl

解决方案


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


推荐阅读