Reputation: 2663
I'm building something like music bot and I decided to host it on heroku. Unfortunatelly it doesn't work properly. Everything works fine, bot connects to a voice channel, but I can't hear any audio playing from bot. Yesterday I got an error (logs from heroku):
2020-08-06T15:13:45.003027+00:00 app[worker.1]: Ignoring exception in on_ready
2020-08-06T15:13:45.004547+00:00 app[worker.1]: Traceback (most recent call last):
2020-08-06T15:13:45.004619+00:00 app[worker.1]: File "/app/.heroku/python/lib/python3.8/site-packages/discord/client.py", line 312, in _run_event
2020-08-06T15:13:45.004620+00:00 app[worker.1]: await coro(*args, **kwargs)
2020-08-06T15:13:45.004623+00:00 app[worker.1]: File "papaj.py", line 58, in on_ready
2020-08-06T15:13:45.004624+00:00 app[worker.1]: voice_client.play(discord.FFmpegPCMAudio(path), after=lambda x: endSong(guild, path))
2020-08-06T15:13:45.004641+00:00 app[worker.1]: File "/app/.heroku/python/lib/python3.8/site-packages/discord/voice_client.py", line 411, in play
2020-08-06T15:13:45.004642+00:00 app[worker.1]: self.encoder = opus.Encoder()
2020-08-06T15:13:45.004644+00:00 app[worker.1]: File "/app/.heroku/python/lib/python3.8/site-packages/discord/opus.py", line 231, in __init__
2020-08-06T15:13:45.004644+00:00 app[worker.1]: raise OpusNotLoaded()
2020-08-06T15:13:45.004672+00:00 app[worker.1]: discord.opus.OpusNotLoaded
But today I somehow fixed it and I'm not getting any error messages, but audio is still not playing from bot. It looks like this:
2020-08-06T15:27:50.232782+00:00 app[worker.1]: [youtube] 1dOt_VcbgyA: Downloading webpage
2020-08-06T15:27:50.736856+00:00 app[worker.1]: [download] Destination: Wykop - Barka (Electro Version)-1dOt_VcbgyA.webm
2020-08-06T15:27:50.875706+00:00 app[worker.1]: [ffmpeg] Destination: Wykop - Barka (Electro Version)-1dOt_VcbgyA.mp3
2020-08-06T15:27:57.656852+00:00 app[worker.1]: Deleting original file Wykop - Barka (Electro Version)-1dOt_VcbgyA.webm (pass -k to keep)
After that it just stops. (When I run it on my computer everything works fine.)
Upvotes: 0
Views: 771
Reputation: 2663
That's how I solved it (when I tried to run it on my computer I got an error, but on Heroku it works perfect).
I added this to my script:
import ctypes
import ctypes.util
print("ctypes - Find opus:")
a = ctypes.util.find_library('opus')
print(a)
print("Discord - Load Opus:")
b = discord.opus.load_opus(a)
print(b)
print("Discord - Is loaded:")
c = discord.opus.is_loaded()
print(c)
Remember to put it before anything linked to audio (the best option is to paste it at the beginning).
Source
Upvotes: 1
Reputation: 13
https://stackoverflow.com/a/55920177/14058810
"According to the discord.py docs you should not need it on a windows environnement, which is maybe why it worked on your local machine and not on heroku (which is unix based)."
Upvotes: 0