首页 > 解决方案 > 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 但它没有用。

标签: pythondiscord.pyopus

解决方案


文档nameThe filename of the shared library.. load_opus()如果库与您的 python 文件不在同一目录中,则您必须为函数提供确切的名称,可能还带有文件路径。


该文件应该被称为

libopus-0-x64.dll

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


推荐阅读