AttributeError:“ffmpegpcAudio”对象没有属性“start”

2024-07-04 07:06:26 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在尝试用discord.py编程一个discord机器人,现在的主要目标是让我的机器人加入一个语音频道,播放我笔记本电脑上的音频文件

@client.command()
async def sing(ctx):
    user = ctx.author.voice
    if user != None:
        channel_chat = ctx.author.voice.channel
        await channel_chat.connect()
        player = discord.FFmpegPCMAudio(executable="C:/Path_Program/ffmpeg.exe", source=r"C:\Users\ialwa\Desktop\Misc\Music\Zelda's Lullaby Ancient Tune Hyrule Warriors Age of Calamity Soundtrack.mp3")
        player.start()
    else:
        await ctx.send("Beep beep! (Be in a voice channel please!)")

这是假设播放文件的代码块,bot可以正常加入频道,但无法播放音频。我确实安装了ffmpeg-python,并且已经尝试安装ffmpeg-python,但两者或一次一个都会带来相同的错误。 错误本身在这里

Ignoring exception in command sing:
Traceback (most recent call last):
  File "C:\Users\ialwa\PycharmProjects\TY\venv\lib\site-packages\discord\ext\commands\core.py", line 85, in wrapped
    ret = await coro(*args, **kwargs)
  File "C:\Users\ialwa\PycharmProjects\TY\main.py", line 29, in sing
    player.start()
AttributeError: 'FFmpegPCMAudio' object has no attribute 'start'

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "C:\Users\ialwa\PycharmProjects\TY\venv\lib\site-packages\discord\ext\commands\bot.py", line 902, in invoke
    await ctx.command.invoke(ctx)
  File "C:\Users\ialwa\PycharmProjects\TY\venv\lib\site-packages\discord\ext\commands\core.py", line 864, in invoke
    await injected(*ctx.args, **ctx.kwargs)
  File "C:\Users\ialwa\PycharmProjects\TY\venv\lib\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: AttributeError: 'FFmpegPCMAudio' object has no attribute 'start'

如果有人能帮助我了解如何解决这个问题,我将不胜感激


Tags: inpylinechannelawaitstartusersext
1条回答
网友
1楼 · 发布于 2024-07-04 07:06:26

^{}不是播放器,它只是一个音频源

要播放音频文件,您需要^{}

@client.command()
async def sing(ctx):
    user = ctx.author.voice
    if user is not None:
        channel = ctx.author.voice.channel
        voice = await channel.connect()
        voice.play(discord.FFmpegPCMAudio(executable="C:/Path_Program/ffmpeg.exe", source=r"C:\Users\ialwa\Desktop\Misc\Music\Zelda's Lullaby Ancient Tune Hyrule Warriors Age of Calamity Soundtrack.mp3"))
    else:
        await ctx.send("Beep beep! (Be in a voice channel please!)")

相关问题 更多 >

    热门问题