Discord.py: Opus not loaded, only occurs on VPS

Created on 16 Sep 2017  路  10Comments  路  Source: Rapptz/discord.py

Whenever I try to make my music bot join a voice channel with this code:

    elif message.content.startswith(";music join") or message.content.startswith(";music j") or message.content.startswith(";m j"):
        try:
            await create_voice_client(message.author.voice_channel)
            await bot.send_message(message.channel, "I joined your voice chat!")
        except discord.errors.InvalidArgument:
            await bot.send_message(message.channel, "You don't seen to be in a voice channel :/")
        except Exception as error:
            await bot.send_message(message.channel, "Error: **{}**".format(error))

It works while running on my PC, but the same code gives me this error on my VPS:

Ignoring exception in on_message
Traceback (most recent call last):
  File "/usr/local/lib/python3.5/dist-packages/discord/client.py", line 307, in _run_event
    yield from getattr(self, event)(*args, **kwargs)
  File "Musicbot.py", line 697, in on_message
    await create_voice_client(message.author.voice_channel)
  File "Musicbot.py", line 38, in create_voice_client
    voice = await bot.join_voice_channel(channel)
  File "/usr/local/lib/python3.5/dist-packages/discord/client.py", line 3209, in join_voice_channel
    voice = VoiceClient(**kwargs)
  File "/usr/local/lib/python3.5/dist-packages/discord/voice_client.py", line 230, in __init__
    self.encoder = opus.Encoder(48000, 2)
  File "/usr/local/lib/python3.5/dist-packages/discord/opus.py", line 197, in __init__
    raise OpusNotLoaded()
discord.opus.OpusNotLoaded

And I can't figure out what's wrong

When I put

if not discord.opus.is_loaded():
    # the 'opus' library here is opus.dll on windows
    # or libopus.so on linux in the current directory
    # you should replace this with the location the
    # opus library is located in and with the proper filename.
    # note that on windows this DLL is automatically provided for you
    discord.opus.load_opus('opus')

at the start of my file, the bot does not start and tells me it didn't find the specified directory. Any idea?

question

Most helpful comment

this Buildpack:
https://github.com/xrisk/heroku-opus.git
will fix it 100%.

All 10 comments

You need to actually get the library. Use your package manager. It's the libopus0 package on Debian-like systems as far as I know.

What's the best was to install this on non-debian systems? I've been porting my bot to a Linux server and have been getting the same error. After viewing this topic I've tried

pip install opus
pip install opuslib
yum install opus

Those didn't work, so I found I need to call

apt-get install libopus0

Which I can't do since it's non-debian. Last night I installed it the old way from github, still doesn't work. One thing I did notice is after installing it, there's no resulting .dll file in the system. Do you think this is too much trouble? Should I give up or am I doing something glaringly wrong?

Just google "libopus [operating system here]" and follow the instructions?

I did. It's not so much that I can't install it, it's that discord.py can't find it. I'm asking if it needs to be in a specific directory

If Discord is having trouble finding the library, it must not be installed, as it uses ctypes.util.find_library which in turn uses ldcache, gcc, and objdump (all of which are GNU commands). Make sure it actually is installed by using sudo ldconfig -p | grep opus.

This worked for me:
https://pastebin.com/U4VsB8XF

Please don't necrobump issues.
For future help like this, you should join either the official discord.py server or the Discord API server, as the README also links.

this Buildpack:
https://github.com/xrisk/heroku-opus.git
will fix it 100%.

@Emad-Fussi
1) As said above, do not necrobump issues.
2) This doesn鈥檛 seem to be anything to do with heroku

@Emad-Fussi

Thanks, I tried deploying my bot on heroku and in my case your solution fixed the issue.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

wolfclaws picture wolfclaws  路  17Comments

Mercurial picture Mercurial  路  22Comments

AceKiron picture AceKiron  路  23Comments

TomOrth picture TomOrth  路  15Comments

rektile picture rektile  路  18Comments