I have noticed lately that the discord bot I have created has a tendency to randomly disconnect and re-connect by itself. This can sometimes happen 4-5 times day. As far as I can tell, the functionality of the bot itself, does not seem to be effected. Is this an expected behavior?
I discovered this issue because I have this function in my code
@bot.event
async def on_ready():
logger.info("[main.py on_ready()] now ready for commands")
@bot.event
async def on_disconnect():
logger.info('[main.py on_disconnect()] experienced a disconnect')
@bot.event
async def on_resumed():
logger.info('[main.py on_resumed()] experienced a resume')
@bot.event
async def on_error(event, *args, **kwargs):
logger.info('[main.py on_error()] experienced the error {}'.format(event))
I had expected for on_ready to be invoked once on initial start-up and perhaps if the system that the bot is running on experiences a temporary network issue. and maybe for on_disconnect to be invoked in those temporary networking issue situations.
the logs channels fills up with multiple calls to on_ready and on_disconnect over the course of a day and sometimes instead of on_ready, on_resumed is called instead.
$ python -m discord -v
- Python v3.7.3-final
- discord.py v1.2.5-final
- aiohttp v3.5.4
- websockets v6.0
- system info: Linux 4.19.0-9-amd64 #1 SMP Debian 4.19.118-2 (2020-04-29)
If you're being reconnected then there's no actual issue here. Consider checking if your internet is cutting out. However library wise there is no issue here.
Hi @Rapptz ,
I do not believe it is my network that is the issue. I ran my bot both on a local computer that has pretty decent network connection and 2 different servers on digitalocean for a full day and both experienced this issue.
I am unsure personally if it is the library or the discord server itself that is causing the problem.
The point remains the same. If you're being reconnected then it's working as intended. There are many reasons for a disconnect including:
etc. etc.
So I'll reiterate: if you're being reconnected there's no issue.
Most helpful comment
The point remains the same. If you're being reconnected then it's working as intended. There are many reasons for a disconnect including:
etc. etc.
So I'll reiterate: if you're being reconnected there's no issue.