guard ext loading

This commit is contained in:
fanyx 2020-11-15 01:37:27 +01:00
parent a1b1787612
commit 47003d0f61
1 changed files with 12 additions and 3 deletions

13
main.py
View File

@ -11,13 +11,22 @@ config = build_config()
# spawn discord bot instance # spawn discord bot instance
# init token from config # init token from config
bot = Bot(command_prefix="~ak ") bot = Bot(command_prefix="~ak ")
token = config['AUTH']['token'] TOKEN = config['AUTH']['token']
# load extensions # load extensions
for file in os.listdir("src/ext"): for file in os.listdir("src/ext"):
if file.endswith(".py"): if file.endswith(".py"):
name = file[:-3] name = file[:-3]
try:
bot.load_extension(f"src.ext.{name}") 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__": if __name__ == "__main__":
bot.run(token) logging.info("Starting bot...")
# use token from config
bot.run(TOKEN)