diff options
| author | bmintz <[email protected]> | 2018-11-02 03:38:50 +0000 |
|---|---|---|
| committer | Rapptz <[email protected]> | 2018-11-24 22:51:16 -0500 |
| commit | 24c0946a93852e0e0c7bd342239d8e39ac7a0fcc (patch) | |
| tree | ea4ed804920316d4d583fc91310d9abe076152e3 | |
| parent | Trim whitespace in artist names in Spotify.artists (diff) | |
| download | discord.py-24c0946a93852e0e0c7bd342239d8e39ac7a0fcc.tar.xz discord.py-24c0946a93852e0e0c7bd342239d8e39ac7a0fcc.zip | |
bot.unload_extension: also allow events with no module
It turns out that events created in an eval command also cause
the issue described in #1506.
Ensure that events we remove are part of a module as well.
Also performs minor comment maintenance
("x", "first y", "then z") -> ("x", "y", "z")
| -rw-r--r-- | discord/ext/commands/bot.py | 10 |
1 files changed, 4 insertions, 6 deletions
diff --git a/discord/ext/commands/bot.py b/discord/ext/commands/bot.py index 3f2f1a80..7bc97f81 100644 --- a/discord/ext/commands/bot.py +++ b/discord/ext/commands/bot.py @@ -734,20 +734,18 @@ class BotBase(GroupMixin): if _is_submodule(lib_name, cog.__module__): self.remove_cog(cogname) - # first remove all the commands from the module + # remove all the commands from the module for cmd in self.all_commands.copy().values(): - if cmd.module is None: - continue - if _is_submodule(lib_name, cmd.module): + if cmd.module is not None and _is_submodule(lib_name, cmd.module): if isinstance(cmd, GroupMixin): cmd.recursively_remove_all_commands() self.remove_command(cmd.name) - # then remove all the listeners from the module + # 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 _is_submodule(lib_name, event.__module__): + if event.__module__ is not None and _is_submodule(lib_name, event.__module__): remove.append(index) for index in reversed(remove): |