discord.py bot 连接到语音通道但 OpusNotLoaded,以及 discord.opus.load_opus() 的问题

问题描述

我正在尝试将我的机器人连接到语音频道,然后播放 mp3 文件
这是我的原始代码

@client.command(name='voice',case_insensitive=True)
async def voice(context):

    channel = context.author.voice.channel

    await channel.connect()

    guild = context.guild
    voice_client: discord.VoiceClient = discord.utils.get(client.voice_clients,guild=guild)

    voice_client.play(discord.FFmpegPCMAudio('voices/bonjour.mp3',executable='/Users/rimelmallah/Desktop/Python/ffmpeg'),after=None)

我收到此错误discord.opus.OpusNotLoaded

所以我在最后一行之前添加了这行代码discord.opus.load_opus()
当我这样做时,我收到了这个错误TypeError: load_opus() missing 1 required positional argument: 'name'

所以我尝试将我的代码修改为:discord.opus.load_opus('opus')
这次我收到以下错误OSError: dlopen(opus,6): image not found

我尝试通过此链接安装 Opus:https://opus-codec.org/release/stable/2019/04/12/libopus-1_3_1.html
但它没有用。

解决方法

The docsnameThe filename of the shared library.。如果库与您的 python 文件不在同一目录中,您将必须为函数 load_opus() 提供确切的名称,大概还包括文件路径。


该文件应该被称为

libopus-0-x64.dll

但是有一些事情需要注意。查看文档以获取更多信息