interactions.py icon indicating copy to clipboard operation
interactions.py copied to clipboard

[BUG] modal_callback

Open Wolfhound905 opened this issue 2 years ago • 2 comments

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

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

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

Wolfhound905 avatar Aug 07 '23 05:08 Wolfhound905

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.

AstreaTSS avatar Aug 07 '23 05:08 AstreaTSS

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.

AstreaTSS avatar Feb 21 '24 23:02 AstreaTSS

The proposal attached needs further testing and review before pass

eightween avatar Mar 13 '24 21:03 eightween