#Multiple Autocompletes

1 messages · Page 1 of 1 (latest)

lusty blade
#

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 🤔

pale pebble
#

You have responded twice, it dosn't work that way

#

Each AC option will generate their own interactions

lusty blade
#

So how do I get the 2nd autocomplete action?

#

@pale pebble

pale pebble
#

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

lusty blade
#

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?

pale pebble
#

Looks good to me.
Although your for loop can just be a filter

lusty blade
#

👀

#

How so

#

I'm definitely not against removing some for loops for something more simple

shadow atlasBOT
#

Documentation suggestion for @lusty blade:
mdn 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.

lusty blade
#

So the for loop goes through profiles pulled from a DB? would that still work? @pale pebble

lusty blade
pale pebble
#
const myArr = [1, 2, 3, 4, 5];
console.log(myArr.filter(val => val > 2));

Results in [3, 4, 5]

lusty blade
#

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.

pale pebble
#

Ah in that case use map

shadow atlasBOT
#

Documentation suggestion for @lusty blade:
mdn 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.

pale pebble
#

As for my name ¯_(ツ)_/¯

lusty blade
#

and the autocomplete2?

#

It returns the same options the first one does :/

pale pebble
#

Your second one should return factions

lusty blade
#

Ah

#

I think it's my interactionCreate

pale pebble
#

Keep in mind I have no idea how your logic is deciding which to run

lusty blade
#

it calls the same autocomplete() again

pale pebble
#

Ah, haha, that'll do it

lusty blade
#

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

pale pebble
#

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;
lusty blade
#

Thanks for the help, I went with this.

#

@pale pebble