auto complete

async autocomplete(interaction) {
const focusedOption = interaction.options.getFocused(true);
let choices;

if (focusedOption.name === '1') {
choices = [
{ cname: `Bob`, cvalue: `test` }
];
}

if (focusedOption.name === '2') {
choices = [

];
}

const filtered = choices.filter(choice => choice.startsWith(focusedOption.value));
await interaction.respond(
filtered.map(choice => ({ name: cname, value: cvalue })),
)
},
async autocomplete(interaction) {
const focusedOption = interaction.options.getFocused(true);
let choices;

if (focusedOption.name === '1') {
choices = [
{ cname: `Bob`, cvalue: `test` }
];
}

if (focusedOption.name === '2') {
choices = [

];
}

const filtered = choices.filter(choice => choice.startsWith(focusedOption.value));
await interaction.respond(
filtered.map(choice => ({ name: cname, value: cvalue })),
)
},
I have this but when i type 1 nothing shows up
4 Replies
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
JollyJohn
JollyJohnOP2y ago
nvm i forgot to save index.js so i now get this
const filtered = choices.filter(choice => choice.startsWith(focusedOption.value));
await interaction.respond(
filtered.map(choice => ({ name: choice, value: choice })),
)
const filtered = choices.filter(choice => choice.startsWith(focusedOption.value));
await interaction.respond(
filtered.map(choice => ({ name: choice, value: choice })),
)
it says filter is undefind..
d.js docs
d.js docs2y ago
ReferenceError: "x" is not defined: learn moreTypeError: Cannot read properties of undefined/null (reading "x"): learn more
JollyJohn
JollyJohnOP2y ago
why would it be returning null or undefined like why would choices be returning that
Want results from more Discord servers?
Add your server