Search code examples
pythondiscord.pyopus

discord.py bot connecting to voice channel but OpusNotLoaded, and problems with discord.opus.load_opus()


I'm trying to connect my bot to a voice channel and then playing an mp3 file.
This was my original code :

@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)

I got this error : discord.opus.OpusNotLoaded

So I added this line of code before the last line : discord.opus.load_opus()
When i did this I got this error : TypeError: load_opus() missing 1 required positional argument: 'name'

So I tried to modify my line of code to : discord.opus.load_opus('opus')
And this time I got the following error : OSError: dlopen(opus, 6): image not found

I tried to install Opus from this link : https://opus-codec.org/release/stable/2019/04/12/libopus-1_3_1.html
but it didn't work.


Solution

  • The docs say that name is The filename of the shared library.. You will have to give the function load_opus() the exact name, presumably also with file path, if the library isn't located in the same directory as your python-file.


    The file should be called something like

    libopus-0-x64.dll
    

    However there are some things to look out for. Look at the docs for further information