fix: stop swallowing startup errors, fix fresh-install crashes on Windows - #7
Open
MeloleM wants to merge 1 commit into
Open
fix: stop swallowing startup errors, fix fresh-install crashes on Windows#7MeloleM wants to merge 1 commit into
MeloleM wants to merge 1 commit into
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #6.
What was wrong
Client.Save()ended withexit(0).Save()runs fromclose(), anddiscord.pycallsclose()inrun()'sfinallyblock, soSystemExitreplaced 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 theexit(0)fromSave().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.py—load_dotenv()behind atry/except ImportError, so a.envnext tomain.pyworks whilepython-dotenvstays optional and system environment variables keep priority. Missingecontokennow prints a readable message and exits1rather than reachingdiscord.pyasNone.saveload/saveload.py—LoadUserDict()calledos.mknod(), which doesn't exist on Windows, thenpickle.load()'d the empty file it had just made. A missing or empty save file is now treated as an emptyuser_dict;SaveUserDict()creates the file on the first save.README.md— added thePrivileged Gateway Intentsstep (all three are required byIntents.all()), documented the.envoption, and addedpython-dotenvto the install line.Verification
Before, with no token set:
After, with no token set:
After, with a valid token but intents not yet enabled in the portal — the error that was being hidden all along:
Enabling the three intents then boots the bot cleanly through to
on_ready:No behaviour change on a healthy startup path.