diff options
| author | Rapptz <[email protected]> | 2017-04-21 18:57:28 -0400 |
|---|---|---|
| committer | Rapptz <[email protected]> | 2017-04-21 18:57:28 -0400 |
| commit | b6ac8568687880418cda73b546c32dc085af7411 (patch) | |
| tree | b72677f27a95c40b7973b10d5c1f720929a89f59 | |
| parent | Allow using Reaction objects while adding or removing reactions. (diff) | |
| download | discord.py-b6ac8568687880418cda73b546c32dc085af7411.tar.xz discord.py-b6ac8568687880418cda73b546c32dc085af7411.zip | |
[commands] Allow loading cogs from folders.
Internally, instead of using module objects just use the `__module__`
attribute which is the same thing. From preliminary testing this seems
to work fine with both regular one-file-per-cog approaches and the
folder cog approach.
Fixes #126.
| -rw-r--r-- | discord/ext/commands/bot.py | 17 | ||||
| -rw-r--r-- | discord/ext/commands/core.py | 2 |
2 files changed, 10 insertions, 9 deletions
diff --git a/discord/ext/commands/bot.py b/discord/ext/commands/bot.py index de5821e5..0f09af84 100644 --- a/discord/ext/commands/bot.py +++ b/discord/ext/commands/bot.py @@ -602,26 +602,27 @@ class BotBase(GroupMixin): if lib is None: return + lib_name = lib.__name__ + # find all references to the module # remove the cogs registered from the module for cogname, cog in self.cogs.copy().items(): - if inspect.getmodule(cog) is lib: + if cog.__module__.startswith(lib_name): self.remove_cog(cogname) # first remove all the commands from the module - for command in self.all_commands.copy().values(): - if command.module is lib: - command.module = None - if isinstance(command, GroupMixin): - command.recursively_remove_all_commands() - self.remove_command(command.name) + for cmd in self.all_commands.copy().values(): + if cmd.module.startswith(lib_name): + if isinstance(cmd, GroupMixin): + cmd.recursively_remove_all_commands() + self.remove_command(cmd.name) # then remove all the listeners from the module for event_list in self.extra_events.copy().values(): remove = [] for index, event in enumerate(event_list): - if inspect.getmodule(event) is lib: + if event.__module__.startswith(lib_name): remove.append(index) for index in reversed(remove): diff --git a/discord/ext/commands/core.py b/discord/ext/commands/core.py index f64e7482..faac03d1 100644 --- a/discord/ext/commands/core.py +++ b/discord/ext/commands/core.py @@ -155,7 +155,7 @@ class Command: signature = inspect.signature(callback) self.params = signature.parameters.copy() self.checks = kwargs.get('checks', []) - self.module = inspect.getmodule(callback) + self.module = callback.__module__ self.ignore_extra = kwargs.get('ignore_extra', True) self.instance = None self.parent = None |