Repository: interactions-py/interactions.py

Issue:
[BUG] Context is missing `command` attribute in the `on_component` event
### Describe the bug.

Taken from [`#AttributeError 'NoneType' object has no attribute 'name'`](https://canary.discord.com/channels/789032594456576001/1033886778165305424/1033886778165305424) in the help forum

In the `on_command` event, there is a possibility that `ctx.command` is None instead of the associated Command instance. This is due to a race condition where some attribute processing for Context is done when the command is being invoked. This issue likely applies to other attributes as well, though that has not been tested yet

A workaround is to call `asyncio.sleep` with a short delay, but users likely won't find that solution on their own

### List the steps.

Set up the client with a command and a listener for the `on_command` event. In the event, access `ctx.command`

### What you expected.

`ctx.command` to be a Command instance 

### What you saw.

`ctx.command` is None

### What version of the library did you use?

release

### Version specification

4.3.2

### Code of Conduct

- [X] I agree to follow the contribution requirements.
[BUG] Context is missing `command` attribute in the `on_component` event
### Describe the bug.

Taken from [`#AttributeError 'NoneType' object has no attribute 'name'`](https://canary.discord.com/channels/789032594456576001/1033886778165305424/1033886778165305424) in the help forum

In the `on_command` event, there is a possibility that `ctx.command` is None instead of the associated Command instance. This is due to a race condition where some attribute processing for Context is done when the command is being invoked. This issue likely applies to other attributes as well, though that has not been tested yet

A workaround is to call `asyncio.sleep` with a short delay, but users likely won't find that solution on their own

### List the steps.

Set up the client with a command and a listener for the `on_command` event. In the event, access `ctx.command`

### What you expected.

`ctx.command` to be a Command instance 

### What you saw.

`ctx.command` is None

### What version of the library did you use?

release

### Version specification

4.3.2

### Code of Conduct

- [X] I agree to follow the contribution requirements.


Discussion:
I see only one solution.
Remove line `self._dispatch.dispatch("on_command", _context)` from `WebSocketClient._dispatch_interaction_event` and paste it into
`Command.__wrap_coro`.
It wont be breaking *I think*
I see only one solution.
Remove line `self._dispatch.dispatch("on_command", _context)` from `WebSocketClient._dispatch_interaction_event` and paste it into
`Command.__wrap_coro`.
It wont be breaking *I think*

Resolving patch:
diff --git a/interactions/api/gateway/client.py b/interactions/api/gateway/client.py
--- a/interactions/api/gateway/client.py
+++ b/interactions/api/gateway/client.py
@@ -404,7 +404,6 @@ def _dispatch_interaction_event(self, data: dict) -> None:
                     _option = self.__sub_command_context(option, _context)
                     __kwargs.update(_option)
 
-            self._dispatch.dispatch("on_command", _context)
         elif data["type"] == InteractionType.MESSAGE_COMPONENT:
             _name = f"component_{_context.data.custom_id}"
 
diff --git a/interactions/client/models/command.py b/interactions/client/models/command.py
--- a/interactions/client/models/command.py
+++ b/interactions/client/models/command.py
@@ -897,6 +897,8 @@ async def wrapper(ctx: "CommandContext", *args, **kwargs):
             ctx.command = self
             ctx.extension = self.extension
 
+            self.listener.dispatch("on_command", ctx)
+
             try:
                 if self.extension:
                     return await coro(self.extension, ctx, *args, **kwargs)


Test patch: