Skip to content

Startup failures are silently swallowed: exit(0) in Client.Save() hides every login/connect error #6

Description

@MeloleM

Summary

Any error during startup is completely invisible. The bot prints the same four lines no matter what went wrong and exits with code 0:

E:\...\saveload/userdata.pkl
[INFO    ] discord.client: logging in using static token
. . . Saved Userdata Successfully !
--- Client disconnected ---

No traceback, no error, no hint. It looks like a clean shutdown.

Cause

Client.Save() in singletons.py ends with exit(0):

async def Save(self):
    await saveload.SaveUserDict()
    print_colored("--- Client disconnected ---", "red")
    exit(0)

async def close(self):
    await self.async_cleanup()   # -> Save() -> exit(0)
    await super().close()

discord.py calls close() from run()'s finally block. So when login() or connect() raises, the cleanup path fires, exit(0) raises SystemExit, and that replaces the in-flight exception before it can be printed. super().close() never runs either.

In my case two separate errors were being hidden this way: first a TypeError (token was None), then PrivilegedIntentsRequired once the token loaded.

Other things found while tracking this down

  • os.mknod doesn't exist on Windows. LoadUserDict() calls it when saveload/userdata.pkl is missing, so a fresh clone crashes on Windows before the bot ever starts. Even where mknod does exist, the next line runs pickle.load() on the newly created empty file and raises EOFError.
  • The README never mentions privileged gateway intents. singletons.py uses discord.Intents.all(), which requires Presence, Server Members and Message Content to be enabled in the developer portal. Without them the bot dies with PrivilegedIntentsRequired — which, thanks to the above, you can't see.
  • .env files aren't supported. The README only documents a system environment variable, so dropping a .env next to main.py (a pretty natural assumption) silently yields econtoken=None.

Repro

  1. Clone, don't set econtoken.
  2. python main.py.
  3. Observe the output above, exit code 0, and no clue that the token is missing.

PR incoming.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions