Repository: interactions-py/interactions.py

Issue:
[BUG] modal_callback
### Library Version

5.8.0

### Describe the Bug

When using the @component_callback I seem to be getting an error related to the ID or Custom ID of an InputText field.

### Minimal Reproducible Code

```python
from interactions import Client, InputText, Modal, SlashContext, TextStyles, modal_callback, slash_command

bot = Client()


@slash_command(name="trigger_modal")
async def trigger_modal(ctx: SlashContext):
    modal = Modal(
        InputText(
            style=TextStyles.PARAGRAPH,
            label="URL (glitchii or discohook)",
            required=True,
            min_length=5,
        ),
        title="Embed Builder",
        custom_id="embed_builder_modal",
    )
    await ctx.send_modal(modal)


@modal_callback("embed_builder_modal")
async def embed_builder_modal(ctx: SlashContext):
    await ctx.send("this is placeholder text")


bot.start("token")
```


### Traceback

```[2023-08-07 05:07:40] [ERROR   ] Ignoring exception in Modal Callback for custom_id embed_builder_modal:
Traceback (most recent call last):
  File "/home/aiden/tfc-bot/.venv/lib/python3.11/site-packages/interactions/client/client.py", line 1890, in __dispatch_interaction
    response = await callback
               ^^^^^^^^^^^^^^
  File "/home/aiden/tfc-bot/.venv/lib/python3.11/site-packages/interactions/models/internal/command.py", line 132, in __call__
    await self.call_callback(self.callback, context)
  File "/home/aiden/tfc-bot/.venv/lib/python3.11/site-packages/interactions/models/internal/command.py", line 198, in call_callback
    await self.call_with_binding(callback, context, **context.kwargs)  # type: ignore
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/aiden/tfc-bot/.venv/lib/python3.11/site-packages/interactions/models/internal/callback.py", line 43, in call_with_binding
    return await callback(*args, **kwargs)
                 ^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: EmbedBuilder.embed_builder_modal() got an unexpected keyword argument 'bb430638-9361-464d-b570-f4304e2f25d7'
```

### 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.
- [X] I have attempted to debug this myself, and I believe this issue is with the library

### Additional Information

_No response_
[BUG] modal_callback
### Library Version

5.8.0

### Describe the Bug

When using the @component_callback I seem to be getting an error related to the ID or Custom ID of an InputText field.

### Minimal Reproducible Code

```python
from interactions import Client, InputText, Modal, SlashContext, TextStyles, modal_callback, slash_command

bot = Client()


@slash_command(name="trigger_modal")
async def trigger_modal(ctx: SlashContext):
    modal = Modal(
        InputText(
            style=TextStyles.PARAGRAPH,
            label="URL (glitchii or discohook)",
            required=True,
            min_length=5,
        ),
        title="Embed Builder",
        custom_id="embed_builder_modal",
    )
    await ctx.send_modal(modal)


@modal_callback("embed_builder_modal")
async def embed_builder_modal(ctx: SlashContext):
    await ctx.send("this is placeholder text")


bot.start("token")
```


### Traceback

```[2023-08-07 05:07:40] [ERROR   ] Ignoring exception in Modal Callback for custom_id embed_builder_modal:
Traceback (most recent call last):
  File "/home/aiden/tfc-bot/.venv/lib/python3.11/site-packages/interactions/client/client.py", line 1890, in __dispatch_interaction
    response = await callback
               ^^^^^^^^^^^^^^
  File "/home/aiden/tfc-bot/.venv/lib/python3.11/site-packages/interactions/models/internal/command.py", line 132, in __call__
    await self.call_callback(self.callback, context)
  File "/home/aiden/tfc-bot/.venv/lib/python3.11/site-packages/interactions/models/internal/command.py", line 198, in call_callback
    await self.call_with_binding(callback, context, **context.kwargs)  # type: ignore
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/aiden/tfc-bot/.venv/lib/python3.11/site-packages/interactions/models/internal/callback.py", line 43, in call_with_binding
    return await callback(*args, **kwargs)
                 ^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: EmbedBuilder.embed_builder_modal() got an unexpected keyword argument 'bb430638-9361-464d-b570-f4304e2f25d7'
```

### 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.
- [X] I have attempted to debug this myself, and I believe this issue is with the library

### Additional Information

_No response_


Discussion:
This happens because `BaseContext` passes along `**ctx.kwargs`, which for modals is basically an alias to `ctx.responses`, to the raw callback itself. Unfortunately, it's not possible to fix this without a breaking change.
I think I might have found a way of fixing this without any breaking changes by detecting how many arguments the callback has and adjusting behavior from there. If it works, I'll PR it in a bit.
This happens because `BaseContext` passes along `**ctx.kwargs`, which for modals is basically an alias to `ctx.responses`, to the raw callback itself. Unfortunately, it's not possible to fix this without a breaking change.
I think I might have found a way of fixing this without any breaking changes by detecting how many arguments the callback has and adjusting behavior from there. If it works, I'll PR it in a bit.

Resolving patch:
diff --git a/interactions/client/client.py b/interactions/client/client.py
--- a/interactions/client/client.py
+++ b/interactions/client/client.py
@@ -1353,6 +1353,17 @@ def add_modal_callback(self, command: ModalCommand) -> None:
             command: The command to add
 
         """
+        # test for parameters that arent the ctx (or self)
+        if command.has_binding:
+            callback = functools.partial(command.callback, None, None)
+        else:
+            callback = functools.partial(command.callback, None)
+
+        if not inspect.signature(callback).parameters:
+            # if there are none, notify the command to just pass the ctx and not kwargs
+            # TODO: just make modal callbacks not pass kwargs at all (breaking)
+            command._just_ctx = True
+
         for listener in command.listeners:
             if isinstance(listener, re.Pattern):
                 if listener in self._regex_component_callbacks.keys():
diff --git a/interactions/models/internal/application_commands.py b/interactions/models/internal/application_commands.py
--- a/interactions/models/internal/application_commands.py
+++ b/interactions/models/internal/application_commands.py
@@ -845,7 +845,13 @@ class ComponentCommand(InteractionCommand):
 
 
 @attrs.define(eq=False, order=False, hash=False, kw_only=True)
-class ModalCommand(ComponentCommand): ...
+class ModalCommand(ComponentCommand):
+    _just_ctx: bool = attrs.field(repr=False, default=False)
+
+    async def call_callback(self, callback: Callable, context: "BaseContext") -> None:
+        if self._just_ctx:
+            return await self.call_with_binding(callback, context)
+        return await super().call_callback(callback, context)
 
 
 def _unpack_helper(iterable: typing.Iterable[str]) -> list[str]:


Test patch: