-
-
Notifications
You must be signed in to change notification settings - Fork 482
Closed
Labels
Milestone
Description
Summary
Extensions are not unloaded properly
Reproduction Steps
- Load and unload an extension
Minimal Reproducible Code
import discord
client = discord.Bot()
client.load_extension('extension')
client.unload_extension('extension')
Expected Results
Extension unloads
Actual Results
Traceback (most recent call last):
File "main.py", line 8, in <module>
client.unload_extension('extension')
File "/opt/virtualenvs/python3/lib/python3.8/site-packages/discord/cog.py", line 764, in unload_extension
self._remove_module_references(lib.__name__)
File "/opt/virtualenvs/python3/lib/python3.8/site-packages/discord/cog.py", line 613, in _remove_module_references
for cmd in self.all_commands.copy().values():
AttributeError: 'Bot' object has no attribute 'all_commands'
Intents
Default
System Information
- Python v3.8.12-final
- py-cord v2.0.0-alpha
- py-cord pkg_resources: v2.0.0a4822+g9feb8c16
- aiohttp v3.7.4.post0
- system info: Linux 5.11.0-1026-gcp Create InteractionContext #29~20.04.1-Ubuntu SMP Fri Jan 7 12:24:31 UTC 2022
Checklist
- I have searched the open issues for duplicates.
- I have shown the entire traceback, if possible.
- I have removed my token from display, if visible.
Additional Context
There are also issues when removing a cog before the bot has registered commands:
Traceback (most recent call last):
File "main.py", line 8, in <module>
client.unload_extension('extension')
File "/opt/virtualenvs/python3/lib/python3.8/site-packages/discord/cog.py", line 764, in unload_extension
self._remove_module_references(lib.__name__)
File "/opt/virtualenvs/python3/lib/python3.8/site-packages/discord/cog.py", line 610, in _remove_module_references
self.remove_cog(cogname)
File "/opt/virtualenvs/python3/lib/python3.8/site-packages/discord/cog.py", line 594, in remove_cog
cog._eject(self)
File "/opt/virtualenvs/python3/lib/python3.8/site-packages/discord/cog.py", line 478, in _eject
bot.remove_application_command(command)
File "/opt/virtualenvs/python3/lib/python3.8/site-packages/discord/bot.py", line 155, in remove_application_command
return self._application_commands.pop(command.id)
KeyError: None
Working on a PR to fix this, just made an issue in case someone beats me to it.