Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
277 views
in Technique[技术] by (71.8m points)

python - Why is my Discord bot not working properly on Heroku?

Maybe I can find answers to my question here in the community. I run a somewhat more complex music bot and this got set up on a fresh server today.

Problem

I've been using Heroku for this bot for a while now and so far there have never been any problems. I then tried to set everything up again today because my hosting time has expired, starting it up also worked fine. But now the following:

I made the following changes in my requirements.txt file:

discord.py == 1.6.0 youtube_dl == 2021.1.16

Together with these settings the bot doesn`t even manage to hold out for 2 minutes and play the music properly. I always got only the following error message:

Shard ID 0 heartbeat blocked for more than 10 seconds.

I reported to the discord.py server, but on version 1.6.0 such changes causing this error were not introduced. So I thought that the problem is with the youtube_dl version. So I kept trying around, set discord.py == 1.5.1 and youtube_dl == 2021.1.8, but again Heroku seems to stop working at some point and now I get the following error code:

WARNING] discord.gateway: Shard ID 0 has stopped responding to the gateway. Closing and restarting.

The bot stops responding, takes too long to start and I have to restart it manually. The funny thing: I also have a bot, which is only on one server and also runs via Heroku, there the errors also occurred, even with my old "settings", when the bot was still running on Heroku.

The latest and longest error I got:

2021-01-24T00:21:34.861555+00:00 app[worker.1]: [2021-01-24 00:21:34] [WARNING] discord.gateway: Shard ID 0 heartbeat blocked for more than 30 seconds.
2021-01-24T00:21:34.861568+00:00 app[worker.1]: Loop thread traceback (most recent call last):
2021-01-24T00:21:34.861568+00:00 app[worker.1]:   File "launcher.py", line 55, in <module>
2021-01-24T00:21:34.861568+00:00 app[worker.1]:     main()
2021-01-24T00:21:34.861569+00:00 app[worker.1]:   File "/app/.heroku/python/lib/python3.7/site-packages/click/core.py", line 1025, in __call__
2021-01-24T00:21:34.861569+00:00 app[worker.1]:     return self.main(*args, **kwargs)
2021-01-24T00:21:34.861569+00:00 app[worker.1]:   File "/app/.heroku/python/lib/python3.7/site-packages/click/core.py", line 955, in main
2021-01-24T00:21:34.861570+00:00 app[worker.1]:     rv = self.invoke(ctx)
2021-01-24T00:21:34.861570+00:00 app[worker.1]:   File "/app/.heroku/python/lib/python3.7/site-packages/click/core.py", line 1496, in invoke
2021-01-24T00:21:34.861571+00:00 app[worker.1]:     super().invoke(ctx)
2021-01-24T00:21:34.861571+00:00 app[worker.1]:   File "/app/.heroku/python/lib/python3.7/site-packages/click/core.py", line 1279, in invoke
2021-01-24T00:21:34.861571+00:00 app[worker.1]:     return ctx.invoke(self.callback, **ctx.params)
2021-01-24T00:21:34.861571+00:00 app[worker.1]:   File "/app/.heroku/python/lib/python3.7/site-packages/click/core.py", line 710, in invoke
2021-01-24T00:21:34.861572+00:00 app[worker.1]:     return callback(*args, **kwargs)
2021-01-24T00:21:34.861572+00:00 app[worker.1]:   File "/app/.heroku/python/lib/python3.7/site-packages/click/decorators.py", line 18, in new_func
2021-01-24T00:21:34.861572+00:00 app[worker.1]:     return f(get_current_context(), *args, **kwargs)
2021-01-24T00:21:34.861573+00:00 app[worker.1]:   File "launcher.py", line 51, in main
2021-01-24T00:21:34.861573+00:00 app[worker.1]:     run_bot()
2021-01-24T00:21:34.861573+00:00 app[worker.1]:   File "launcher.py", line 42, in run_bot
2021-01-24T00:21:34.861573+00:00 app[worker.1]:     bot.run()
2021-01-24T00:21:34.861573+00:00 app[worker.1]:   File "/app/bot.py", line 144, in run
2021-01-24T00:21:34.861574+00:00 app[worker.1]:     super().run(parser.get('DISCORD', 'token'), reconnect=True)
2021-01-24T00:21:34.861574+00:00 app[worker.1]:   File "/app/.heroku/python/lib/python3.7/site-packages/discord/client.py", line 698, in run
2021-01-24T00:21:34.861574+00:00 app[worker.1]:     loop.run_forever()
2021-01-24T00:21:34.861574+00:00 app[worker.1]:   File "/app/.heroku/python/lib/python3.7/asyncio/base_events.py", line 541, in run_forever
2021-01-24T00:21:34.861575+00:00 app[worker.1]:     self._run_once()
2021-01-24T00:21:34.861575+00:00 app[worker.1]:   File "/app/.heroku/python/lib/python3.7/asyncio/base_events.py", line 1786, in _run_once
2021-01-24T00:21:34.861575+00:00 app[worker.1]:     handle._run()
2021-01-24T00:21:34.861575+00:00 app[worker.1]:   File "/app/.heroku/python/lib/python3.7/asyncio/events.py", line 88, in _run
2021-01-24T00:21:34.861575+00:00 app[worker.1]:     self._context.run(self._callback, *self._args)
2021-01-24T00:21:34.861576+00:00 app[worker.1]:   File "/app/.heroku/python/lib/python3.7/site-packages/discord/shard.py", line 151, in worker
2021-01-24T00:21:34.861576+00:00 app[worker.1]:     await self.ws.poll_event()
2021-01-24T00:21:34.861576+00:00 app[worker.1]:   File "/app/.heroku/python/lib/python3.7/site-packages/discord/gateway.py", line 564, in poll_event
2021-01-24T00:21:34.861576+00:00 app[worker.1]:     await self.received_message(msg.data)
2021-01-24T00:21:34.861576+00:00 app[worker.1]:   File "/app/.heroku/python/lib/python3.7/site-packages/discord/gateway.py", line 427, in received_message
2021-01-24T00:21:34.861577+00:00 app[worker.1]:     msg = self._zlib.decompress(self._buffer)
2021-01-24T00:21:34.861577+00:00 app[worker.1]: 
2021-01-24T00:21:39.861332+00:00 app[worker.1]: [2021-01-24 00:21:39] [WARNING] discord.gateway: Shard ID None voice heartbeat blocked for more than 20 seconds
2021-01-24T00:21:39.861369+00:00 app[worker.1]: Loop thread traceback (most recent call last):
2021-01-24T00:21:39.861370+00:00 app[worker.1]:   File "launcher.py", line 55, in <module>
2021-01-24T00:21:39.861371+00:00 app[worker.1]:     main()
2021-01-24T00:21:39.861371+00:00 app[worker.1]:   File "/app/.heroku/python/lib/python3.7/site-packages/click/core.py", line 1025, in __call__
2021-01-24T00:21:39.861372+00:00 app[worker.1]:     return self.main(*args, **kwargs)
2021-01-24T00:21:39.861372+00:00 app[worker.1]:   File "/app/.heroku/python/lib/python3.7/site-packages/click/core.py", line 955, in main
2021-01-24T00:21:39.861372+00:00 app[worker.1]:     rv = self.invoke(ctx)
2021-01-24T00:21:39.861373+00:00 app[worker.1]:   File "/app/.heroku/python/lib/python3.7/site-packages/click/core.py", line 1496, in invoke
2021-01-24T00:21:39.861373+00:00 app[worker.1]:     super().invoke(ctx)
2021-01-24T00:21:39.861373+00:00 app[worker.1]:   File "/app/.heroku/python/lib/python3.7/site-packages/click/core.py", line 1279, in invoke
2021-01-24T00:21:39.861374+00:00 app[worker.1]:     return ctx.invoke(self.callback, **ctx.params)
2021-01-24T00:21:39.861374+00:00 app[worker.1]:   File "/app/.heroku/python/lib/python3.7/site-packages/click/core.py", line 710, in invoke
2021-01-24T00:21:39.861375+00:00 app[worker.1]:     return callback(*args, **kwargs)
2021-01-24T00:21:39.861375+00:00 app[worker.1]:   File "/app/.heroku/python/lib/python3.7/site-packages/click/decorators.py", line 18, in new_func
2021-01-24T00:21:39.861375+00:00 app[worker.1]:     return f(get_current_context(), *args, **kwargs)
2021-01-24T00:21:39.861376+00:00 app[worker.1]:   File "launcher.py", line 51, in main
2021-01-24T00:21:39.861376+00:00 app[worker.1]:     run_bot()
2021-01-24T00:21:39.861376+00:00 app[worker.1]:   File "launcher.py", line 42, in run_bot
2021-01-24T00:21:39.861376+00:00 app[worker.1]:     bot.run()
2021-01-24T00:21:39.861376+00:00 app[worker.1]:   File "/app/bot.py", line 144, in run
2021-01-24T00:21:39.861377+00:00 app[worker.1]:     super().run(parser.get('DISCORD', 'token'), reconnect=True)
2021-01-24T00:21:39.861377+00:00 app[worker.1]:   File "/app/.heroku/python/lib/python3.7/site-packages/discord/client.py", line 698, in run
2021-01-24T00:21:39.861377+00:00 app[worker.1]:     loop.run_forever()
2021-01-24T00:21:39.861377+00:00 app[worker.1]:   File "/app/.heroku/python/lib/python3.7/asyncio/base_events.py", line 541, in run_forever
2021-01-24T00:21:39.861378+00:00 app[worker.1]:     self._run_once()
2021-01-24T00:21:39.861378+00:00 app[worker.1]:   File "/app/.heroku/python/lib/python3.7/asyncio/base_events.py", line 1786, in _run_once
2021-01-24T00:21:39.861378+00:00 app[worker.1]:     handle._run()
2021-01-24T00:21:39.861379+00:00 app[worker.1]:   File "/app/.heroku/python/lib/python3.7/asyncio/events.py", line 88, in _run
2021-01-24T00:21:39.861379+00:00 app[worker.1]:     self._context.run(self._callback, *self._args)
2021-01-24T00:21:39.861379+00:00 app[worker.1]:   File "/app/.heroku/python/lib/python3.7/site-packages/discord/shard.py", line 151, in worker
2021-01-24T00:21:39.861379+00:00 app[worker.1]:     await self.ws.poll_event()
2021-01-24T00:21:39.861379+00:00 app[worker.1]:   File "/app/.heroku/python/lib/python3.7/site-packages/discord/gateway.py", line 564, in poll_event
2021-01-24T00:21:39.861380+00:00 app[worker.1]:     await self.received_message(msg.data)
2021-01-24T00:21:39.861380+00:00 app[worker.1]:   File "/app/.heroku/python/lib/python3.7/site-packages/discord/gateway.py", line 427, in received_message
2021-01-24T00:21:39.861380+00:00 app[worker.1]:     msg = self._zlib.decompress(self._buffer)
2021-01-24T00:21:39.861380+00:00 app[worker.1]:

To the Python buildpack I have installed the following things:

https://github.com/xrisk/heroku-opus

https://github.com/jonathanong/heroku-buildpack-ffmpeg-latest

Could the error be due to these buildpacks, although it always worked before? I just don't know at the moment, because of course everything works locally. Also upgrading to newer modules or versions from my requirements.txt file always causes problems with Heroku or doesn't let the bot start.

Is there a recommendation which python version to use with Heroku? Currently I define with a runtime.txt the version 3.7.9.

question from:https://stackoverflow.com/questions/65865817/why-is-my-discord-bot-not-working-properly-on-heroku

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...