[V3 Core] Add optional async setup function (#1314)

This commit is contained in:
Will
2018-02-18 21:12:58 -05:00
committed by GitHub
parent 86b5932c8f
commit b871241eac
3 changed files with 9 additions and 5 deletions

View File

@@ -172,7 +172,7 @@ class RedBase(BotBase, RpcMethodMixin):
while pkg_name in curr_pkgs:
curr_pkgs.remove(pkg_name)
def load_extension(self, spec: ModuleSpec):
async def load_extension(self, spec: ModuleSpec):
name = spec.name.split('.')[-1]
if name in self.extensions:
return
@@ -182,7 +182,11 @@ class RedBase(BotBase, RpcMethodMixin):
del lib
raise discord.ClientException('extension does not have a setup function')
lib.setup(self)
if asyncio.iscoroutinefunction(lib.setup):
await lib.setup(self)
else:
lib.setup(self)
self.extensions[name] = lib
def unload_extension(self, name):