#Autocomplete

47 messages · Page 1 of 1 (latest)

fierce acorn
#

Anyone knows how can i do this ? in my autocomplete im limited to 25 choices and if the user dont type anything theres just an error

oak badger
#

• What's your exact discord.js npm list discord.js and node node -v version?
• Post the full error stack trace, not just the top part!
• Show your code!
• Explain what exactly your issue is.
• Not a discord.js issue? Check out #useful-servers.

fierce acorn
#

mine

cunning skiff
#

Because you don't response if user didn't type anything

fierce acorn
#

why in that command that i showed it does?

#

is there anything i can do to make it like that?

cunning skiff
#

Response to autocomplete interaction

#

If you need help with your code then show it

fierce acorn
#
        .setName('create')
        .setDescription('Cria uma ficha de Breed')
        .addStringOption(option => 
            option.setName('dinoname')
            .setDescription('Dino que sera breedado')
            .setRequired(true)
            .setAutocomplete(true)),
            
            async autocomplete(interaction){
                const focusedValue = interaction.options.getFocused();
                const choices = ['Giga', 'Stego', 'Charca', 'Carbo', 'Tape', 'Velona', 'Snow', 'Barionyx', 'Tuso', 'Desmodus', 'Shadow', 'Astro', 'Theri', 'Stalker', 'Racer', 'Rex', 'Basilo', 'FjordHawk', 'Andrewsarchus', 'Amargasaurus', 'Noglin', 'Basilisk', 
                'Griffin', 'Daeodon', 'Thyla', 'Mantis', 'Voidwyrm', 'Deino', 'Yutirannus', 'LightWyvern']
                const filtered = choices.filter(choice => choice.startsWith(focusedValue));
                await interaction.respond(
                    filtered.map(choice => ({ name: choice, value: choice })),
                );
            },```
#
        const {commands} = client;
        const {commandName} = interaction;
        const command = commands.get(commandName);
        if (!command) return;

        try {
        await command.autocomplete(interaction, client)
        } catch (error){
            console.error(error);
        }```
#

last one is interactioncreate.js

cunning skiff
#

You should splice first 25 elements

#

Sorry, splice

fierce acorn
#

all good

#

after i splice it , how do i proceed?

main void
#

The same way you already do

fierce acorn
#

kk , so i gotta do choices.splice(0, 24) ?

main void
#

slice not splice, but yeah (wait, why did Syjalo suggest splice?Thonk )

fierce acorn
#

ok , thx

#

didnt work

main void
cunning skiff
fierce acorn
main void
fierce acorn
#

tested the splice but only the options after 25th showed up, then tested slice and only the choices before 25 showed up

main void
fierce acorn
#

used only 1 of them

main void
#

And you need to .filter(…).splice(…) not the other way around

fierce acorn
#

but i did it

#

look at the screenshot

main void
# fierce acorn

And that should give you up to 25 options that pass the filter, doesn’t it?

fierce acorn
#

i mean , im trynna gett an option that is after the position of 25 in the array but i cant

#

not an option , a choice

main void
#

There is only Ligh* in your choices

#

Use toLowerCase() in the filter to ignore case

fierce acorn
main void
fierce acorn
#

focusedValue.toLowerCase() ?

#

idk if the error is cause of the case sensitive

#

even with L didnt work

main void