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

15
main.py
View File

@ -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)
logging.info("Starting bot...")
# use token from config
bot.run(TOKEN)