From 47003d0f6120726d6cd7b6c420e27ef6e46f2ce1 Mon Sep 17 00:00:00 2001 From: fanyx Date: Sun, 15 Nov 2020 01:37:27 +0100 Subject: [PATCH] guard ext loading --- main.py | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/main.py b/main.py index 79e7cc6..d3a4e6a 100644 --- a/main.py +++ b/main.py @@ -11,13 +11,22 @@ config = build_config() # spawn discord bot instance # init token from config bot = Bot(command_prefix="~ak ") -token = config['AUTH']['token'] +TOKEN = config['AUTH']['token'] # load extensions for file in os.listdir("src/ext"): if file.endswith(".py"): name = file[:-3] - bot.load_extension(f"src.ext.{name}") + try: + bot.load_extension(f"src.ext.{name}") + except NoEntryPointError: + logging.error(f"Extension {name} cannot be loaded. [No setup function]") + except ExtensionFailed: + logging.error(f"Extension {name} failed to load. [Execution error]") + + logging.info("Finished loading extensions.") if __name__ == "__main__": - bot.run(token) \ No newline at end of file + logging.info("Starting bot...") + # use token from config + bot.run(TOKEN) \ No newline at end of file