diff --git a/redbot/__main__.py b/redbot/__main__.py index 66b64cc57..77c01ba52 100644 --- a/redbot/__main__.py +++ b/redbot/__main__.py @@ -288,7 +288,18 @@ def handle_edit(cli_flags: Namespace): sys.exit(0) -async def run_bot(red: Red, cli_flags: Namespace) -> NoReturn: +async def run_bot(red: Red, cli_flags: Namespace) -> None: + """ + This runs the bot. + + Any shutdown which is a result of not being able to log in needs to raise + a SystemExit exception. + + If the bot starts normally, the bot should be left to handle the exit case. + It will raise SystemExit in a task, which will reach the event loop and + interrupt running forever, then trigger our cleanup process, and does not + need additional handling in this function. + """ driver_cls = drivers.get_driver_class() @@ -335,7 +346,6 @@ async def run_bot(red: Red, cli_flags: Namespace) -> NoReturn: sys.exit(0) try: await red.start(token, bot=True, cli_flags=cli_flags) - # This raises SystemExit in normal use at close except discord.LoginFailure: log.critical("This token doesn't seem to be valid.") db_token = await red._config.token() @@ -344,7 +354,9 @@ async def run_bot(red: Red, cli_flags: Namespace) -> NoReturn: await red._config.token.set("") print("Token has been reset.") sys.exit(0) - sys.exit(1) + sys.exit(1) + + return None def handle_early_exit_flags(cli_flags: Namespace):