Autocomplete

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
20 Replies
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
Ashura
AshuraOP2y ago
mine
Ashura
AshuraOP2y ago
Syjalo
Syjalo2y ago
Because you don't response if user didn't type anything
Ashura
AshuraOP2y ago
why in that command that i showed it does? is there anything i can do to make it like that?
Syjalo
Syjalo2y ago
Response to autocomplete interaction If you need help with your code then show it
Ashura
AshuraOP2y ago
new SlashCommandBuilder()
.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 })),
);
},
new SlashCommandBuilder()
.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 })),
);
},
if(interaction.type == InteractionType.ApplicationCommandAutocomplete){
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);
}
if(interaction.type == InteractionType.ApplicationCommandAutocomplete){
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
Syjalo
Syjalo2y ago
You should splice first 25 elements Sorry, splice
Ashura
AshuraOP2y ago
all good after i splice it , how do i proceed? kk , so i gotta do choices.splice(0, 24) ? ok , thx
Ashura
AshuraOP2y ago
didnt work
Syjalo
Syjalo2y ago
To do array.filter().splice(25)?
Ashura
AshuraOP2y ago
oh , sorry tested the splice but only the options after 25th showed up, then tested slice and only the choices before 25 showed up
Ashura
AshuraOP2y ago
Ashura
AshuraOP2y ago
used only 1 of them
Ashura
AshuraOP2y ago
Ashura
AshuraOP2y ago
but i did it look at the screenshot
Ashura
AshuraOP2y ago
i mean , im trynna gett an option that is after the position of 25 in the array but i cant
Ashura
AshuraOP2y ago
not an option , a choice like this ? const filtered = choices.filter(choice => choice.startsWith(focusedValue).toLowerCase()).slice(0, 25); any example of it ? i didnt get it focusedValue.toLowerCase() ? idk if the error is cause of the case sensitive
Ashura
AshuraOP2y ago
Ashura
AshuraOP2y ago
even with L didnt work y but not even with the Caps L ist working
Want results from more Discord servers?
Add your server