Repository: Pycord-Development/pycord

Issue:
Bridge commands doesn't work with unloading or reloading cogs
### Summary

if you make your bot a bridge bot, and try to unload or reload a cog it'll fail

### Reproduction Steps

1. Make a bridge bot
2. Make a cog
3. Unload or reload that (or another) cog
4. Done

### Minimal Reproducible Code

```python
from discord.ext import bridge
bot = bridge.Bot()
bot.load_extension("cog") #Loads all cogs in the cogs folder
bot.run(TOKEN)
```
Now in a another file called cog.py
```py
from discord.ext import commands, bridge
class Name(commands.Cog):
    def __init__(self, bot):
        self.bot = bot

    @bridge.bridge_command()
    async def ping(self, ctx):
        await ctx.respond ("Pong!")

    @bridge.bridge_command()
    async def action(self, ctx):
        self.bot.unload_extension("cog")
        #self.bot.reload_extension("cog") Same applies
        await ctx.respond ("Observe the error.")

def setup(bot):
    bot.add_cog(Name(bot))
```


### Expected Results

The cog is unloaded or reloaded

### Actual Results

The cog is not unloaded or reloaded

### Intents

guilds=True, guild_messages=True

### System Information

- Python v3.11.1-final
- py-cord v2.3.2-final
- aiohttp v3.7.4.post0
- system info: Windows 10 10.0.22621 (Not true, im actually running windows 11)

### Checklist

- [X] I have searched the open issues for duplicates.
- [X] I have shown the entire traceback, if possible.
- [X] I have removed my token from display, if visible.

### Additional Context

Tracebacl:
Ignoring exception in on_application_command_error
Traceback (most recent call last):
  File "C:\Users\MYPCNAME\AppData\Local\Programs\Python\Python311\Lib\site-packages\discord\commands\core.py", line 124, in wrapped
    ret = await coro(arg)
          ^^^^^^^^^^^^^^^
  File "C:\Users\MYPCNAME\AppData\Local\Programs\Python\Python311\Lib\site-packages\discord\commands\core.py", line 976, in _invoke
    await self.callback(self.cog, ctx, **kwargs)
  File "C:\Users\MYPCNAME\Documents\GitHub\pingernos-py\cogs\cogs.py", line 34, in cogs
    raise e
  File "C:\Users\MYPCNAME\Documents\GitHub\pingernos-py\cogs\cogs.py", line 29, in cogs
    self.bot.unload_extension(f"cogs.{cog}") (Same happens with reload_extension)
  File "C:\Users\MYPCNAME\AppData\Local\Programs\Python\Python311\Lib\site-packages\discord\cog.py", line 1066, in unload_extension
    self._remove_module_references(lib.__name__)
  File "C:\Users\MYPCNAME\AppData\Local\Programs\Python\Python311\Lib\site-packages\discord\cog.py", line 722, in _remove_module_references
    self.remove_cog(cog_name)
  File "C:\Users\MYPCNAME\AppData\Local\Programs\Python\Python311\Lib\site-packages\discord\cog.py", line 706, in remove_cog
    cog._eject(self)
  File "C:\Users\MYPCNAME\AppData\Local\Programs\Python\Python311\Lib\site-packages\discord\cog.py", line 592, in _eject
    bot.remove_command(command.name)
                       ^^^^^^^^^^^^
AttributeError: 'BridgeCommand' object has no attribute 'name'

Its not the same code as the code i gave, but there's almost no difference and the error will still happen, i also tried it on my other cogs and the same happened.


Discussion:

Resolving patch:
diff --git a/discord/cog.py b/discord/cog.py
--- a/discord/cog.py
+++ b/discord/cog.py
@@ -586,7 +586,10 @@ def _eject(self, bot) -> None:
 
         try:
             for command in self.__cog_commands__:
-                if isinstance(command, ApplicationCommand):
+                if hasattr(command, "add_to"):
+                    bot.bridge_commands.remove(command)
+                    continue
+                elif isinstance(command, ApplicationCommand):
                     bot.remove_application_command(command)
                 elif command.parent is None:
                     bot.remove_command(command.name)


Test patch: