属性错误:"FFmpegPCMAudio"对象没有属性"start"



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

@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:UsersialwaDesktopMiscMusicZelda'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,但一次安装两个或一个会带来相同的错误。错误本身的完整内容在这里

Ignoring exception in command sing:
Traceback (most recent call last):
File "C:UsersialwaPycharmProjectsTYvenvlibsite-packagesdiscordextcommandscore.py", line 85, in wrapped
ret = await coro(*args, **kwargs)
File "C:UsersialwaPycharmProjectsTYmain.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:UsersialwaPycharmProjectsTYvenvlibsite-packagesdiscordextcommandsbot.py", line 902, in invoke
await ctx.command.invoke(ctx)
File "C:UsersialwaPycharmProjectsTYvenvlibsite-packagesdiscordextcommandscore.py", line 864, in invoke
await injected(*ctx.args, **ctx.kwargs)
File "C:UsersialwaPycharmProjectsTYvenvlibsite-packagesdiscordextcommandscore.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'

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

discord.FFmpegPCMAudio不是播放器,它只是一个音频源。

为了播放音频文件,你需要discord.VoiceClient.play:

@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:UsersialwaDesktopMiscMusicZelda's Lullaby Ancient Tune Hyrule Warriors Age of Calamity Soundtrack.mp3"))
else:
await ctx.send("Beep beep! (Be in a voice channel please!)")

相关内容

最新更新