mirror of
https://github.com/Rapptz/discord.py.git
synced 2025-09-05 17:36:15 +00:00
[commads] Change cog/extension load/unload methods to be async
This commit is contained in:
@ -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
|
||||
|
||||
|
Reference in New Issue
Block a user