[commands] Add deterministic cog unloading.
The special function is `__unload` to prevent with name conflicts with existing or future cogs.
This commit is contained in:
parent
8b7f15ef8d
commit
82b2421ac7
@ -462,6 +462,10 @@ class Bot(GroupMixin, discord.Client):
|
|||||||
If no cog is found then ``None`` is returned, otherwise
|
If no cog is found then ``None`` is returned, otherwise
|
||||||
the cog instance that is being removed is returned.
|
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
|
Parameters
|
||||||
-----------
|
-----------
|
||||||
name : str
|
name : str
|
||||||
@ -485,6 +489,12 @@ class Bot(GroupMixin, discord.Client):
|
|||||||
if name.startswith('on_'):
|
if name.startswith('on_'):
|
||||||
self.remove_listener(member)
|
self.remove_listener(member)
|
||||||
|
|
||||||
|
unloader_name = '_{0.__class__.__name__}__unload'.format(cog)
|
||||||
|
try:
|
||||||
|
getattr(cog, unloader_name)()
|
||||||
|
except AttributeError:
|
||||||
|
pass
|
||||||
|
|
||||||
del cog
|
del cog
|
||||||
|
|
||||||
# extensions
|
# extensions
|
||||||
|
Loading…
x
Reference in New Issue
Block a user