Skip to content

[BUG] Autocomplete error with 2 required options #729

@Aluminoti

Description

@Aluminoti

Describe the bug.

When trying to create a slash command with two options

@bot.command(name="split", description="Submit a split for contributions",
options=[
    interactions.Option(
        type=interactions.OptionType.STRING,
        name="item",
        description="Start typing and select the item you received.",
        autocomplete=True,
        required=True
    ),
    interactions.Option(
        type=interactions.OptionType.STRING,
        name="players",
        description="Tag each player you split the item with.",
        required=True,
    ),
])

@bot.autocomplete(command="split", name="item")
async def do_autocomplete(ctx, item: str = ""):
    choices = []
    item_list = get_item_list()
    for item_name in item_list:
        choices.append(Choice(name=item_name, value=item_name))

    to_send = []
    for choice in choices:
        if choice.name.lower().startswith(item.lower()):
            to_send.append(choice)
    await ctx.populate(to_send[:25])

upon getting to the option that is required and also has the autocomplete logic (regardless of order) the bot will throw an error (seen in what you saw section).

In this specific example, if I set the required flag = False for the "players" option, no error occurs and the command can function as I expect.

List the steps.

  1. Create a command with two required options, one of them having autocomplete=True
  2. Implement the autocomplete logic for the autocomplete option
  3. Run the bot
  4. Type /command_here -> both options will pop up with blank values associated and will throw the error

What you expected.

I expected to be able to create a command with two required parameters, allowing one of the required parameters to have some autocomplete logic.

The following code meat works but does not allow for me to set the "players" option to required=True or it will break.

@bot.command(name="split", description="Submit a split for contributions", scope=963757034501726249,
options=[
    interactions.Option(
        type=interactions.OptionType.STRING,
        name="item",
        description="Start typing and select the item you received.",
        autocomplete=True,
        required=True
    ),
    interactions.Option(
        type=interactions.OptionType.STRING,
        name="players",
        description="Tag each player you split the item with.",
        required=False, # <-------------------------------------------------------- Issue lies here
    ),

])
async def split(ctx: CommandContext, item: str, players: str = ''):
    await ctx.defer()
    item_details = get_item_details_from_wiki(item)
    if item_details is None:
        return await ctx.send(f"Could not find item: ``{item}``")

    print(players)

    await ctx.send(str(item_details))


@bot.autocomplete(command="split", name="item")
async def do_autocomplete(ctx, item: str = ""):
    choices = []
    item_list = get_item_list()
    for item_name in item_list:
        choices.append(Choice(name=item_name, value=item_name))

    to_send = []
    for choice in choices:
        if choice.name.lower().startswith(item.lower()):
            to_send.append(choice)
    await ctx.populate(to_send[:25])

What you saw.

I received this traceback error given from my Python terminal when having two required options. The following error only shows once I move to the option that is required AND has autocomplete=True. In this case it would be the "item" option.

Traceback (most recent call last):
  File "C:\Users\Erik\PycharmProjects\cb2\bot.py", line 300, in <module>
    bot.start()
  File "C:\Users\Erik\PycharmProjects\cb2\venv\lib\site-packages\interactions\client.py", line 109, in start
    self._loop.run_until_complete(self._ready())
  File "C:\Users\Erik\AppData\Local\Programs\Python\Python39\lib\asyncio\base_events.py", line 642, in run_until_complete
    return future.result()
  File "C:\Users\Erik\PycharmProjects\cb2\venv\lib\site-packages\interactions\client.py", line 307, in _ready
    await self._login()
  File "C:\Users\Erik\PycharmProjects\cb2\venv\lib\site-packages\interactions\client.py", line 312, in _login
    await self._websocket._establish_connection(self._shard, self._presence)
  File "C:\Users\Erik\PycharmProjects\cb2\venv\lib\site-packages\interactions\api\gateway.py", line 209, in _establish_connection
    await self._handle_connection(stream, shard, presence)
  File "C:\Users\Erik\PycharmProjects\cb2\venv\lib\site-packages\interactions\api\gateway.py", line 277, in _handle_connection
    self._dispatch_event(event, data)
  File "C:\Users\Erik\PycharmProjects\cb2\venv\lib\site-packages\interactions\api\gateway.py", line 358, in _dispatch_event
    __name, _value = self.__sub_command_context(option, _context)
ValueError: not enough values to unpack (expected 2, got 0)

Process finished with exit code 1

What version of the library did you use?

stable

Version specification

4.1.0

Code of Conduct

  • I agree to follow the contribution requirements.

Metadata

Metadata

Labels

bugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions