#Autocomplete
47 messages · Page 1 of 1 (latest)
• 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.
Because you don't response if user didn't type anything
why in that command that i showed it does?
is there anything i can do to make it like that?
.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
The same way you already do
kk , so i gotta do choices.splice(0, 24) ?
slice not splice, but yeah (wait, why did Syjalo suggest splice?
)
slice the result of the filter…
To do array.filter().splice(25)?
oh , sorry
I’m not a fan of splice for that use-case but effectively has the same outcome as slice(0,25) here, but wouldn’t if you‘d splice the original array itself before filtering
tested the splice but only the options after 25th showed up, then tested slice and only the choices before 25 showed up
Because you didn’t use what Syjalo said, splice(25) or slice(0,25) not a mix of both
And you need to .filter(…).splice(…) not the other way around
And that should give you up to 25 options that pass the filter, doesn’t it?
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
Because you filter case sensitive…
There is only Ligh* in your choices
Use toLowerCase() in the filter to ignore case
like this ? const filtered = choices.filter(choice => choice.startsWith(focusedValue).toLowerCase()).slice(0, 25);
No… <boolean>.toLowerCase() doesn’t exist… call it on the two strings you have there
any example of it ? i didnt get it
focusedValue.toLowerCase() ?
idk if the error is cause of the case sensitive
even with L didnt work
You also need to lowercase the choice you compare it to.