Discord.py: multiple disconnects experienced in a day

Created on 28 Jun 2020  路  3Comments  路  Source: Rapptz/discord.py

Summary

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?

Reproduction Steps

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))

Expected Results

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.

Actual Results

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.

Checklist

  • [x] I have searched the open issues for duplicates.
  • [x] I have shown the entire traceback, if possible.
  • [x] I have removed my token from display, if visible.

System Information


    $ 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)
question

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:

  1. Your internet goes down.
  2. There's a blip in the connection between you and Discord.
  3. Discord tells you to disconnect (happens periodically every 15 minutes to 2 hours) and then the subsequent reconnection fails to RESUME and falls back to an IDENTIFY.
  4. A RESUME fails and you get told to IDENTIFY.
  5. Discord has terminated your connection since the packet died somewhere along the way causing a TCP RST packet.
  6. The WebSocket became a zombie and was unable to ping back with a heartbeat in time for some reason.

etc. etc.

So I'll reiterate: if you're being reconnected there's no issue.

All 3 comments

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:

  1. Your internet goes down.
  2. There's a blip in the connection between you and Discord.
  3. Discord tells you to disconnect (happens periodically every 15 minutes to 2 hours) and then the subsequent reconnection fails to RESUME and falls back to an IDENTIFY.
  4. A RESUME fails and you get told to IDENTIFY.
  5. Discord has terminated your connection since the packet died somewhere along the way causing a TCP RST packet.
  6. The WebSocket became a zombie and was unable to ping back with a heartbeat in time for some reason.

etc. etc.

So I'll reiterate: if you're being reconnected there's no issue.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

PicklesJars picture PicklesJars  路  3Comments

ghost picture ghost  路  3Comments

TunaHobby picture TunaHobby  路  3Comments

MrBrahm picture MrBrahm  路  3Comments

Spyder-exe picture Spyder-exe  路  3Comments