#Multiple Autocompletes
1 messages · Page 1 of 1 (latest)
Running into this:
Error during autocomplete
Error: Error [InteractionAlreadyReplied]: The reply to this interaction has already been sent or deferred.
I assume because I'm responding to the interaction twice, but how can I reply with the choices for the 2nd parameter 🤔
You have responded twice, it dosn't work that way
Each AC option will generate their own interactions
Depends how you want to structure the code for them
They can't be apart of the slash command,'s execute,n they could be extea functions on the command's exports
Ideally if I could get autocomplete2 to work, that'd be awesome.
This way, it returns the same choices from the first autocomplete though.
do I just overwrite the choices object from the first autocomplete with the new choices?
Looks good to me.
Although your for loop can just be a filter
👀
How so
I'm definitely not against removing some for loops for something more simple
Documentation suggestion for @lusty blade:
Array.prototype.filter()
The filter() method creates a shallow copy of a portion of a given array, filtered down to just the elements from the given array that pass the test implemented by the provided function.
So the for loop goes through profiles pulled from a DB? would that still work? @pale pebble
What exactly looks good, because the 2nd autocomplete doesn't seem to work the way they are. 😦
const myArr = [1, 2, 3, 4, 5];
console.log(myArr.filter(val => val > 2));
Results in [3, 4, 5]
Your name is really familiar for some reason
Not positive that would work, because my for loop doesn't really filter out an array, it just grabs a few values from every object returned.
Ah in that case use map
Documentation suggestion for @lusty blade:
Array.prototype.map()
The map() method creates a new array populated with the results of calling a provided function on every element in the calling array.
As for my name ¯_(ツ)_/¯
Your second one should return factions
Keep in mind I have no idea how your logic is deciding which to run
it calls the same autocomplete() again
Ah, haha, that'll do it
Thanks
Is there a way to pull the parameter/option name? @pale pebble
So I can add an if statement/switch based on the parameter
There is 2 secs
I did this, there might however be a more effecient way:
let optionsActual = interaction.options.data.length
&& [
ApplicationCommandOptionType.SubcommandGroup, // 'SUB_COMMAND_GROUP',
ApplicationCommandOptionType.Subcommand, // 'SUB_COMMAND'
].includes(interaction.options.data[0].type)
? interaction.options.data[0].options
: interaction.options.data;