def unload_extension(self, extension_name): # horrible hacks to make cogs work with single process sharding
for shard in self.shards.values():
if not extension_name in shard.extensions.keys():
continue
ext_lib = shard.extensions[extension_name]
# print("removing cogs")
for cog_name, cog in shard.cogs.copy().items():
if get_module(cog) is ext_lib:
shard.remove_cog(cog_name)
# print("removing commands")
for command in shard.commands.copy().values():
if command.module is ext_lib:
command.module = None
if isinstance(command, commands.GroupMixin):
command.recursively_remove_all_commands()
shard.remove_command(command.name)
# print("removing events")
for event_list in shard.extra_events.copy().values():
remove = []
for idx, event in enumerate(event_list):
if get_module(event) is ext_lib:
remove.append(idx)
for idx in reversed(remove):
del event_list[idx]
# print("tearing down")
try:
teardown_func = getattr(ext_lib, "teardown")
except AttributeError:
pass
else:
try:
func(shard)
except:
pass
finally:
del shard.extensions[extension_name]
del self.extensions[extension_name]
del sys.modules[extension_name]
# print("finished")
评论列表
文章目录