discord / discord-api-docs

Official Discord API Documentation
https://discord.com/developers/docs/intro
Other
5.85k stars 1.23k forks source link

Autocomplete shouldn't use cached results when another option has changed #4804

Open abitofevrything opened 2 years ago

abitofevrything commented 2 years ago

Description

Sometimes, the choices an application returns for an autocomplete interaction can depend on the values of other options that the user may or may not have filled in. This works fine most of the time, but when the results for an option are cached and the value of a different option changes, the cached result is still used for the original option even though the application might have responded differently when the other option changed.

Steps to Reproduce

  1. Create a slash command with two options, option A with autocomplete enabled.
  2. Set up the autocomplete handler in a way that the values returned for option A autocompletion depend on the value of option B (a simple setup to reproduce: have the choices be what the user has currently typed in B if they have typed anything, else return some constant value).
  3. Fill in option B, then see what autocomplete value is suggested for A. It should be the value entered in B.
  4. Cancel the previous command and instead let the autocomplete load for option A (producing the constant value), then fill in B. Switching back to option A, the suggested autocompletion is still the constant value and not the value we just entered in B.

Expected Behavior

The cached autocompletion results should be invalidated whenever any option changes, not just the option the completions are for.

Current Behavior

Cached autocompletion results are still used when another option changes.

Screenshots/Videos

ezgif com-gif-maker

Code used: https://gist.github.com/abitofevrything/7a1c633ca060d044e0fb3daa5b86ccd7

Client and System Information

Library used in video: nyxx

Elitesparkle commented 1 year ago

Any update? I encountered this issue today and I'm wondering when it will be fixed.

Vioshim commented 1 year ago

Same here, it's been a bit of an issue with making the full transition to slash commands

nerblock commented 1 year ago

This is very problematic for our usecase. We needed to setup many slash commands instead of just one because of this behaviour. It would be nice to have caching based on the combination of all the options of a given command.

Scrxtchy commented 1 year ago

Having this issue too. I have some code that is fetching leaderboard data from a website, a user is able to use a non-required field to filter the result to a single player name, but as the leaderboard data has different requests per course we rely on data in a required field to provide autocomplete results to the user.

I believe it would be nice to provide the API with a list of required options for another option to be available to a user, and if any of these options have their value changed, delete the cache

XCanG commented 4 days ago

I had a similar case, which I originally described in library discussion, I would also like to have separate cache when multiple fields being used.