discord-akwah/main.py

32 lines
905 B
Python
Raw Normal View History

2020-11-13 01:49:39 +01:00
import logging
import sys
2020-11-13 15:51:12 +01:00
from os import listdir
2020-11-13 01:49:39 +01:00
2020-11-13 15:51:12 +01:00
from discord.ext.commands import Bot
from src.utils.config import build_config
2020-11-13 01:49:39 +01:00
2020-11-13 15:51:12 +01:00
# read config at configured location \\ default to 'config.ini'
config = build_config()
# spawn discord bot instance
2020-11-13 01:49:39 +01:00
# init token from config
2020-11-13 15:51:12 +01:00
bot = Bot(command_prefix="~ak ")
2020-11-15 01:37:27 +01:00
TOKEN = config['AUTH']['token']
2020-11-13 01:49:39 +01:00
2020-11-13 15:51:12 +01:00
# load extensions
2020-11-13 15:53:55 +01:00
for file in os.listdir("src/ext"):
2020-11-13 15:51:12 +01:00
if file.endswith(".py"):
name = file[:-3]
2020-11-15 01:37:27 +01:00
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.")
2020-11-13 15:51:12 +01:00
2020-11-13 01:49:39 +01:00
if __name__ == "__main__":
2020-11-15 01:37:27 +01:00
logging.info("Starting bot...")
# use token from config
bot.run(TOKEN)