How can i make this code not be case sensitive?

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)).slice(0, 25);
await interaction.respond(
filtered.map(choice => ({ name: choice, value: choice })),
);
},
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)).slice(0, 25);
await interaction.respond(
filtered.map(choice => ({ name: choice, value: choice })),
);
},
9 Replies
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
Ashura
Ashura2y ago
didnt work TypeError: choice.startsWith(...).toLowerCase is not a function
Syjalo
Syjalo2y ago
Use .toLowerCase() on focusedValue and choice Btw use <#869652447881207858> for not related to discord.js questions
Ashura
Ashura2y ago
srry , forgot bout it const filtered = choices.filter(choice => choice.startsWith(focusedValue.toLowerCase()).toLowerCase()).slice(0, 25);?
Syjalo
Syjalo2y ago
Use first toLowerCase and then startsWith
Ashura
Ashura2y ago
TypeError: choices.toLowerCase is not a function
Syjalo
Syjalo2y ago
Not on choices
Ashura
Ashura2y ago
still TypeError: choice.toLowerCase(...).startsWith(...).toLowerCase is not a function im dumb im so dumb TypeError: choice.toLowerCase(...).startsWith(...) is not a function idk why it wont work
Syjalo
Syjalo2y ago
You have this choice => choice.startsWith(focusedValue) Just use .toLowerCase() on focusedValue
choice => choice.startsWith(focusedValue.toLowerCase())
choice => choice.startsWith(focusedValue.toLowerCase())
And on choice
choice => choice.toLowerCase().startsWith(focusedValue.toLowerCase())
choice => choice.toLowerCase().startsWith(focusedValue.toLowerCase())
That is what I told you