【问题标题】:discord.py bot connecting to voice channel but OpusNotLoaded, and problems with discord.opus.load_opus()discord.py bot 连接到语音通道但 OpusNotLoaded,以及 discord.opus.load_opus() 的问题
【发布时间】:2021-05-18 04:41:00
【问题描述】:

我正在尝试将我的机器人连接到语音频道,然后播放 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
但它没有用。

【问题讨论】:

    标签: python discord.py opus


    【解决方案1】:

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


    文件应该被称为

    libopus-0-x64.dll
    

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

    【讨论】:

    • 我将行更改为:discord.opus.load_opus('libopus-0.x64.dll')(这是我的 Mac 上的文件名),但出现另一个错误:OSError: dlopen(libopus-0.x64.dll, 6): no suitable image found. Did find: libopus-0.x64.dll: unknown file type, first eight bytes: 0x4D 0x5A 0x90 0x00 0x03 0x00 0x00 0x00 /Users/rimelmallah/Desktop/Python/projects/discord_bot/libopus-0.x64.dll: unknown file type, first eight bytes: 0x4D 0x5A 0x90 0x00 0x03 0x00 0x00 0x00
    • "在我的 Mac 上" - 如果您使用的是 Mac,.dll 对您没有多大帮助,因为它仅适用于 Windows。确保您已安装 opus 库 python3 -m pip install -U "discord.py[voice]" 并查看 this thread
    • 谢谢你的帖子帮助我理解了这个问题。我只需要brew install opus
    猜你喜欢
    • 2020-12-06
    • 2022-01-05
    • 2021-08-05
    • 2017-07-31
    • 2020-02-19
    • 2021-04-29
    • 2019-08-02
    • 2020-10-26
    • 1970-01-01
    相关资源
    最近更新 更多