Repository: Pycord-Development/pycord

Issue:
Subgroup having MISSING cog attribute
### Summary

The bot raises Attribute error when you invoke a subcommand under a subgroup under a command group

### Reproduction Steps

1. Create a command group
2. Create a subgroup under it
3. Create a command under it
4. Invoke the command

### Minimal Reproducible Code

```python
group = bot.create_group("test1")
subgroup = group.create_subgroup("test2")

@subgroup.command()
async def test3(ctx):
   ...
```


### Expected Results

Run the command

### Actual Results

Raises an error

```py
Traceback (most recent call last):
  File "d:\Personal\Documents\GitHub\Grass-bot-rewrite\.venv\Lib\site-packages\discord\commands\core.py", line 131, in wrapped
    ret = await coro(arg)
          ^^^^^^^^^^^^^^^
  File "d:\Personal\Documents\GitHub\Grass-bot-rewrite\.venv\Lib\site-packages\discord\commands\core.py", line 1365, in _invoke
    await command.invoke(ctx)
  File "d:\Personal\Documents\GitHub\Grass-bot-rewrite\.venv\Lib\site-packages\discord\commands\core.py", line 378, in invoke
    await self.prepare(ctx)
  File "d:\Personal\Documents\GitHub\Grass-bot-rewrite\.venv\Lib\site-packages\discord\commands\core.py", line 299, in prepare
    if not await self.can_run(ctx):
           ^^^^^^^^^^^^^^^^^^^^^^^
  File "d:\Personal\Documents\GitHub\Grass-bot-rewrite\.venv\Lib\site-packages\discord\commands\core.py", line 396, in can_run
    local_check = cog._get_overridden_method(cog.cog_check)
                  ^^^^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: '_MissingSentinel' object has no attribute '_get_overridden_method'
```

### Intents

All

### System Information

- Python v3.11.5-final
- py-cord v2.4.1-final
- aiohttp v3.8.6
- system info: Windows 10 10.0.22621

### 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

#1594 should have fixed it but it only fixed for commands under a group but not commands under a subgroup


Discussion:

Resolving patch:
diff --git a/discord/commands/core.py b/discord/commands/core.py
--- a/discord/commands/core.py
+++ b/discord/commands/core.py
@@ -846,7 +846,7 @@ def _is_typing_annotated(self, annotation):
 
     @property
     def cog(self):
-        return getattr(self, "_cog", MISSING)
+        return getattr(self, "_cog", None)
 
     @cog.setter
     def cog(self, val):
@@ -1162,7 +1162,7 @@ def __init__(
 
         self._before_invoke = None
         self._after_invoke = None
-        self.cog = MISSING
+        self.cog = None
         self.id = None
 
         # Permissions
@@ -1238,10 +1238,7 @@ def to_dict(self) -> dict:
         return as_dict
 
     def add_command(self, command: SlashCommand) -> None:
-        # check if subcommand has no cog set
-        # also check if cog is MISSING because it
-        # might not have been set by the cog yet
-        if command.cog is MISSING and self.cog is not MISSING:
+        if command.cog is None and self.cog is not None:
             command.cog = self.cog
 
         self.subcommands.append(command)


Test patch: