MenuDocs / Pyro

A Python Discord Bot
Apache License 2.0
26 stars 6 forks source link

main.py running bot & loading cogs #3

Closed Skelmis closed 4 years ago

Skelmis commented 4 years ago

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"])
ribosomerocker commented 4 years ago

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

ribosomerocker commented 4 years ago

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