Skip to content

fix: stop swallowing startup errors, fix fresh-install crashes on Windows - #7

Open
MeloleM wants to merge 1 commit into
DEVUCP:mainfrom
MeloleM:fix/silent-startup-failure
Open

fix: stop swallowing startup errors, fix fresh-install crashes on Windows#7
MeloleM wants to merge 1 commit into
DEVUCP:mainfrom
MeloleM:fix/silent-startup-failure

Conversation

@MeloleM

@MeloleM MeloleM commented Aug 15, 2026

Copy link
Copy Markdown

Closes #6.

What was wrong

Client.Save() ended with exit(0). Save() runs from close(), and discord.py calls close() in run()'s finally block, so SystemExit replaced whatever exception actually killed startup. Every failure — bad token, missing token, missing intents — produced the same silent output and exit code 0.

Changes

singletons.py — drop the exit(0) from Save(). close() now completes normally and the original exception propagates and prints. Shutdown still saves and still prints --- Client disconnected ---; the process just exits on its own instead of being killed mid-cleanup.

main.pyload_dotenv() behind a try/except ImportError, so a .env next to main.py works while python-dotenv stays optional and system environment variables keep priority. Missing econtoken now prints a readable message and exits 1 rather than reaching discord.py as None.

saveload/saveload.pyLoadUserDict() called os.mknod(), which doesn't exist on Windows, then pickle.load()'d the empty file it had just made. A missing or empty save file is now treated as an empty user_dict; SaveUserDict() creates the file on the first save.

README.md — added the Privileged Gateway Intents step (all three are required by Intents.all()), documented the .env option, and added python-dotenv to the install line.

Verification

Before, with no token set:

[INFO    ] discord.client: logging in using static token
. . . Saved Userdata Successfully !
--- Client disconnected ---

After, with no token set:

[ NO TOKEN FOUND ! ]
Set an environment variable named 'econtoken', or put econtoken=<your token> in a .env file next to main.py.

After, with a valid token but intents not yet enabled in the portal — the error that was being hidden all along:

discord.errors.PrivilegedIntentsRequired: Shard ID None is requesting privileged intents that have not
been explicitly enabled in the developer portal.

Enabling the three intents then boots the bot cleanly through to on_ready:

[ VALIDATING SETTINGS . . . ]
...
[ LOADED USER DATA ]
[ INITIATING AUTO-SAVE . . . ]
--- LOGGED IN AS econbot ---

No behaviour change on a healthy startup path.

Client.Save() called exit(0), and Save() runs from close(), which
discord.py calls in run()'s finally block. Any exception raised during
login or connect was therefore replaced by SystemExit before the
traceback could print, so every startup failure looked identical:

    logging in using static token
    . . . Saved Userdata Successfully !
    --- Client disconnected ---

with no indication of what actually went wrong. Removing exit(0) lets
close() finish normally and the original exception propagate.

Also:
- Load a .env file when python-dotenv is available, and print a clear
  message instead of a TypeError when econtoken is unset.
- LoadUserDict() called os.mknod(), which doesn't exist on Windows, and
  then pickle.load() on the empty file it created. Treat a missing or
  empty save file as an empty user_dict instead.
- Document the privileged gateway intents in the README. Intents.all()
  requires all three, and skipping them raises PrivilegedIntentsRequired.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

1 participant