我正在构建音乐机器人之类的东西,因此决定将其托管在heroku上。不幸的是,它无法正常工作。一切正常,机器人已连接到语音通道,但我听不到机器人播放的任何音频。昨天我遇到了一个错误(来自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
但是今天我以某种方式修复了该问题,并且没有收到任何错误消息,但是仍然无法从机器人播放音频。它看起来像这样:
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)
之后,它就停止了。 (在计算机上运行时,一切正常。)
答案 0 :(得分:0)
https://stackoverflow.com/a/55920177/14058810
“根据discord.py文档,您不应该在Windows环境中使用它,这也许就是为什么它在您的本地计算机上而不是在heroku(基于unix的)上运行的原因。”
答案 1 :(得分:0)
这就是我解决的方法 (当我尝试在计算机上运行它时出现错误,但在Heroku上运行正常)。
我将此添加到了脚本中:
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)
请记住将其放在与音频相关的任何内容之前(最好的选择是将其粘贴在开头)。
Source