[commads] Change cog/extension load/unload methods to be async

This commit is contained in:
Josh
2022-03-14 11:03:45 +10:00
committed by GitHub
parent a339e01047
commit a1c618215e
8 changed files with 210 additions and 50 deletions

View File

@ -66,9 +66,11 @@ import config
class Bot(commands.{base}):
def __init__(self, **kwargs):
super().__init__(command_prefix=commands.when_mentioned_or('{prefix}'), **kwargs)
async def setup_hook(self):
for cog in config.cogs:
try:
self.load_extension(cog)
await self.load_extension(cog)
except Exception as exc:
print(f'Could not load extension {{cog}} due to {{exc.__class__.__name__}}: {{exc}}')
@ -122,12 +124,16 @@ class {name}(commands.Cog{attrs}):
def __init__(self, bot):
self.bot = bot
{extra}
def setup(bot):
bot.add_cog({name}(bot))
async def setup(bot):
await bot.add_cog({name}(bot))
'''
_cog_extras = '''
def cog_unload(self):
async def cog_load(self):
# loading logic goes here
pass
async def cog_unload(self):
# clean up logic goes here
pass