aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRapptz <[email protected]>2016-04-04 04:45:15 -0400
committerRapptz <[email protected]>2016-04-04 04:45:15 -0400
commit82b2421ac70d0869cef7d20d8ce333e1a774f145 (patch)
treed67fbda7957a3ff7eff678066798cd73564c389b
parentSkip member_update event when a member is not in a guild. (diff)
downloaddiscord.py-82b2421ac70d0869cef7d20d8ce333e1a774f145.tar.xz
discord.py-82b2421ac70d0869cef7d20d8ce333e1a774f145.zip
[commands] Add deterministic cog unloading.
The special function is `__unload` to prevent with name conflicts with existing or future cogs.
-rw-r--r--discord/ext/commands/bot.py10
1 files changed, 10 insertions, 0 deletions
diff --git a/discord/ext/commands/bot.py b/discord/ext/commands/bot.py
index d8bc6cfb..9b4e44ef 100644
--- a/discord/ext/commands/bot.py
+++ b/discord/ext/commands/bot.py
@@ -462,6 +462,10 @@ class Bot(GroupMixin, discord.Client):
If no cog is found then ``None`` is returned, otherwise
the cog instance that is being removed is returned.
+ If the cog defines a special member function named ``__unload``
+ then it is called when removal has completed. This function
+ **cannot** be a coroutine. It must be a regular function.
+
Parameters
-----------
name : str
@@ -485,6 +489,12 @@ class Bot(GroupMixin, discord.Client):
if name.startswith('on_'):
self.remove_listener(member)
+ unloader_name = '_{0.__class__.__name__}__unload'.format(cog)
+ try:
+ getattr(cog, unloader_name)()
+ except AttributeError:
+ pass
+
del cog
# extensions