MenuDocs/Pyro

main.py running bot & loading cogs

Skelmis opened this issue · 2 comments

Running the bot and loading cogs should be within a if name is main statement to avoid issues where we might import the file etc.

if __name__ == "__main__":
    # Loop over every file in the cogs dir
    for file in os.listdir(cwd+"/cogs"):
        # If the file is a python file and does not start with an _
        # assume it is a cog and attempt to load it
        if file.endswith(".py") and not file.startswith("_"):
            try:
                bot.load_extension(f"cogs.{file[:-3]}")
            except Exception as e:
                logger.error(f"Failed to load cog: {file[:-3]}\n{e}")

    bot.run(config["token"])

I just finished fixing this issue in my dev-impr branch.

I'm going to close since this is a duplicate of #2