Catalyst4222 / wait_for

An extension library for interactions.py to add a waiting method in a manner similar to discord.py
MIT License
11 stars 1 forks source link

[BUG] TypeError: ExtendedListener.dispatch() got multiple values for argument 'name' #4

Closed sgoudham closed 2 years ago

sgoudham commented 2 years ago

Hi, I'm a new user of interactions-py and interactions-wait-for

What Is The Error?

Upon installing the library and trying to set up interactions, I've been getting the error below:

Traceback (most recent call last):
  File "D:\Programming\University\exclamation-mark-charity\exclamation_mark_charity\runner.py", line 58, in <module>
    main()
  File "D:\Programming\University\exclamation-mark-charity\exclamation_mark_charity\runner.py", line 54, in main
    bot.start()
  File "D:\Programming\University\exclamation-mark-charity\venv\lib\site-packages\interactions\client\bot.py", line 115, in start
    self._loop.run_until_complete(self._ready())
  File "C:\Users\sgoud\AppData\Local\Programs\Python\Python310\lib\asyncio\base_events.py", line 646, in run_until_complete
    return future.result()
  File "D:\Programming\University\exclamation-mark-charity\venv\lib\site-packages\interactions\client\bot.py", line 326, in _ready
    await self._login()
  File "D:\Programming\University\exclamation-mark-charity\venv\lib\site-packages\interactions\client\bot.py", line 331, in _login
    await self._websocket._establish_connection(self._shard, self._presence)
  File "D:\Programming\University\exclamation-mark-charity\venv\lib\site-packages\interactions\api\gateway\client.py", line 189, in _establish_connection
    await self._handle_connection(stream, shard, presence)
  File "D:\Programming\University\exclamation-mark-charity\venv\lib\site-packages\interactions\api\gateway\client.py", line 257, in _handle_connection
    self._dispatch_event(event, data)
  File "D:\Programming\University\exclamation-mark-charity\venv\lib\site-packages\interactions\api\gateway\client.py", line 339, in _dispatch_event
    self._dispatch.dispatch(_name, *__args, **__kwargs)
TypeError: ExtendedListener.dispatch() got multiple values for argument 'name'

How Does It Occur?

I believe it occurs when slash commands are registered with subcommands that have options.

Working Example

The following example works as expected:

interactions.extension_command(
    name="click",
    description="click command",
    scope=GUILD_ID,
    options=[
        interactions.Option(
            name="here",
            description="Click Here!",
            type=interactions.OptionType.SUB_COMMAND,
            options=[]
        )
    ]
)
async def test(self, ctx, sub_command: str):
    button1 = interactions.Button(
        style=interactions.ButtonStyle.PRIMARY,
        label="Click Here",
        custom_id="click",
    )

    await ctx.send("grabbing a click...", components=button1)

    async def check(button_ctx):
        if int(button_ctx.author.user.id) == int(ctx.author.user.id):
            return True
        await ctx.send("I wasn't asking you!", ephemeral=True)
        return False

    try:
        button_ctx: ComponentContext = await self.bot.wait_for_component(
            components=button1, check=check, timeout=5
        )
    except asyncio.TimeoutError:
        return await ctx.send("You didn't click :(")

Output: image

Bugged Example

The following example does not work as expected:

interactions.extension_command(
    name="click",
    description="click command",
    scope=GUILD_ID,
    options=[
        interactions.Option(
            name="here",
            description="Click Here!",
            type=interactions.OptionType.SUB_COMMAND,
            options=[
                interactions.Option(
                    name="name",
                    description="Name of click",
                    type=interactions.OptionType.STRING,
                    required=True,
                )
            ]
        )
    ]
)
async def test(self, ctx, sub_command: str, name: str):
    button1 = interactions.Button(
        style=interactions.ButtonStyle.PRIMARY,
        label="Click Here",
        custom_id="click",
    )

    await ctx.send("grabbing a click...", components=button1)

    async def check(button_ctx):
        if int(button_ctx.author.user.id) == int(ctx.author.user.id):
            return True
        await ctx.send("I wasn't asking you!", ephemeral=True)
        return False

    try:
        button_ctx: ComponentContext = await self.bot.wait_for_component(
            components=button1, check=check, timeout=5
        )
    except asyncio.TimeoutError:
        return await ctx.send("You didn't click :(")

Output: image

The error within the terminal is the same as displayed at the beginning.

Diagnostic Details

Operating System: Windows 11 Python: 3.10 interactions-py: 4.1.1-rc.1 interactions-wait-for: 1.0.4

Catalyst4222 commented 2 years ago

I believe that issue is from one of the options being named "name". Can you try running the second example without wait_for anywhere, just await ctx.send("Recieved")?

sgoudham commented 2 years ago

Ahhhh I can't believe that was the problem, works perfectly now thank you! @Catalyst4222 I feel like that should be documented as I never would have thought that! Are there any other keywords that should be avoided?

Catalyst4222 commented 2 years ago

I believe that it's just "name", and possibly "self" too. Since the error originates from the base library, I suggest making an issue there so that the bug gets tracked