Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Autocomplete alternate syntax does not support reading adjacent options #1045

Closed
3 tasks done
DenverCoder1 opened this issue Apr 24, 2023 · 0 comments · Fixed by #1046
Closed
3 tasks done

Autocomplete alternate syntax does not support reading adjacent options #1045

DenverCoder1 opened this issue Apr 24, 2023 · 0 comments · Fixed by #1046
Labels
t: unconfirmed bug Type: bug - needs testing on if this is an issue

Comments

@DenverCoder1
Copy link
Collaborator

DenverCoder1 commented Apr 24, 2023

Summary

Options that are not focused are inaccessible when setting the autocomplete_callback in a SlashOption

Reproduction Steps

Example 1 is working as expected. Example 2 below causes an error since the other options are not getting passed to the autocomplete callback.

Minimal Reproducible Code

class Testing(commands.Cog):

    # Example 1 (working)

    @nextcord.slash_command()
    async def example1(self, interaction: Interaction, state: str, city: str):
        await interaction.response.send_message(f"You chose {state} and {city}")

    @example1.on_autocomplete("city")
    async def example1_autocomplete(self, interaction: Interaction, city: str, state: Optional[str]):
        await interaction.response.send_autocomplete([f"City: {city}", f"State: {state}"])

    # Example 2 (not working)

    async def example2_autocomplete(self, interaction: Interaction, city: str, state: Optional[str]):
        await interaction.response.send_autocomplete([f"City: {city}", f"State: {state}"])

    @nextcord.slash_command()
    async def example2(
        self,
        interaction: Interaction,
        state: str,
        city: str = SlashOption(autocomplete_callback=example2_autocomplete),
    ):
        await interaction.response.send_message(f"You chose {state} and {city}")

Expected Results

Working, as it does in example 1:

image

Actual Results

Error when running example 2:

Ignoring exception in on_interaction
Traceback (most recent call last):
File ".venv/lib/python3.10/site-packages/nextcord/client.py", line 490, in _run_event
    await coro(*args, **kwargs)
File ".venv/lib/python3.10/site-packages/nextcord/client.py", line 2000, in on_interaction
    await self.process_application_commands(interaction)
File ".venv/lib/python3.10/site-packages/nextcord/client.py", line 2076, in process_application_commands
    await app_cmd.call_autocomplete_from_interaction(interaction)  # type: ignore
File ".venv/lib/python3.10/site-packages/nextcord/application_command.py", line 1062, in call_autocomplete_from_interaction
    await self.call_autocomplete(self._state, interaction)
File ".venv/lib/python3.10/site-packages/nextcord/application_command.py", line 1131, in call_autocomplete
    value = await focused_option.invoke_autocomplete_callback(
File ".venv/lib/python3.10/site-packages/nextcord/application_command.py", line 1030, in invoke_autocomplete_callback
    return await self.autocomplete_callback(
TypeError: Testing.example2_autocomplete() missing 1 required positional argument: 'state'
Ignoring exception in on_interaction
Traceback (most recent call last):
File ".venv/lib/python3.10/site-packages/nextcord/client.py", line 490, in _run_event
    await coro(*args, **kwargs)
File ".venv/lib/python3.10/site-packages/nextcord/client.py", line 2000, in on_interaction
    await self.process_application_commands(interaction)
File ".venv/lib/python3.10/site-packages/nextcord/client.py", line 2076, in process_application_commands
    await app_cmd.call_autocomplete_from_interaction(interaction)  # type: ignore
File ".venv/lib/python3.10/site-packages/nextcord/application_command.py", line 1062, in call_autocomplete_from_interaction
    await self.call_autocomplete(self._state, interaction)
File ".venv/lib/python3.10/site-packages/nextcord/application_command.py", line 1131, in call_autocomplete
    value = await focused_option.invoke_autocomplete_callback(
File ".venv/lib/python3.10/site-packages/nextcord/application_command.py", line 1030, in invoke_autocomplete_callback
    return await self.autocomplete_callback(
TypeError: Testing.example2_autocomplete() missing 1 required positional argument: 'state'

Intents

default

System Information

  • Python v3.10.10-final
  • nextcord v2.4.0-final
  • aiohttp v3.8.4
  • system info: Linux 6.2.12-zen1-1-zen # 1 ZEN SMP PREEMPT_DYNAMIC Thu, 20 Apr 2023 16:11:27 +0000

Checklist

  • I have searched the open issues for duplicates.
  • I have shown the entire traceback, if possible.
  • I have removed my token from display, if visible.

Additional Context

  • Current workaround is to use example1 syntax rather than example2 syntax.

  • from_autocomplete_callback is not getting called and autocomplete_options is not getting populated

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
t: unconfirmed bug Type: bug - needs testing on if this is an issue
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant