Bot not going offline when disconnecting

Kommentarer

6 kommentarer

  • SuhEugene

    This is not a discord problem, but the library itself. It does not close the connection when the program is turned off, since the bot could be that it was an unplanned bot crash. Because in order for the bot to turn off, you need to write a separate way to turn it off completely.

    When you create a production server and your bot crashes, it reconnects to the discord after a couple of seconds and continues working. In this case, it is not profitable to close the connection - it will have to be reopened, and not restored (messages sent during these two seconds of inclusion may be lost).

    2
  • squeegily#7499

    > This is not a discord problem, but the library itself.

    SuhEugene, that's what I thought, too—it certainly looks that way—but the library developer [who also owns the unofficial-but-linked-to-by-official-docs API support server] is extremely sure that it's not his code's fault.

    and (despite my statement in the screenshot) I [now] think he might actually be right, though Discord's support staff disagrees:

    The proof-of-concept code can be reduced to a mere 8 SLOC:

    import os, discord
    
    client = discord.Client()
    
    @client.event
    async def on_message(message):
    	if message.author == client.user: return
    	await message.channel.send("https://discord.com/developers/docs/topics/gateway#disconnections\n> When you close the connection to the gateway with the close code 1000 or 1001, your session will be invalidated and your bot will appear offline.")
    	await client.close()
    
    client.run(os.environ['token'])
    

    —i.e. there is little-to-no room for fault to lie in this code → leaving only the library, and Discord, as possible weak links. (But, like I said, I think I believe the library developer's claims that his code is sound.)

    1
  • SuhEugene

    SuhEugene, that's what I thought, too—it certainly looks that way—but the library developer [who also owns the unofficial-but-linked-to-by-official-docs API support server] is extremely sure that it's not his code's fault.

    @squeegily,
    Ohh... You got me wrong. I meant not that the developer is to blame for the error, but that, as intended - the bot will be online for a while

    1
  • squeegily#7499

    > as intended - the bot will be online for a while

    SuhEugene that's the thing, though—this is not the intended behavior. I don't know where you're getting that impression, given that I've quoted and repeatedly linked to the documentation on this, which states otherwise.

    When the bot is "gracefully" closed (i.e. Discord's servers receive a 1000 or 1001 code from the websocket before its TCP connection closes), its Presence should go offline immediately.


    Though, embarassingly, it looks like this whole thing is, in fact, a bug in the library (a regression bug, to be specific): they switched from websockets to aiohttp, which either has its own internal bugs w/r/t closing, or isn't being interfaced with properly by the library… I'll have to hammer that out myself, at some point. *sigh*.

    1
  • Snowsgiving Diorteno.

    It's normal, bots always stay online for 1/2 minutes after stopping them, but their functions doesn't work

    0
  • squeegily#7499

    Snowsgiving Diorteno. If this is normal for everyone, then I'm requesting that the Discord team fix this; that's not how it should work.

    The documentation linked in the OP states:

    Disconnecting

    When you close the connection to the gateway with the close code 1000 or 1001, your session will be invalidated and your bot will appear offline. If you simply close the TCP connection, or use a different close code, the bot session will remain active and timeout after a few minutes…

    0

Log ind for at efterlade en kommentar.