AutoComplete Problem
before:-
after code:-
the autocomplete option named tag does not show any options, it used to show earlier but then i added the hidden option and a switch statement then it stopped working
async autocomplete(interaction: AutocompleteInteraction) {
const focusedValue = interaction.options.getFocused();
try {
const choices = Docs.filter((tag: TagData) => tag.name.startsWith(focusedValue));
await interaction.respond(
choices.map((choice: TagData) => ({ name: choice.name, value: choice.name }))
);
} catch (error) {
await interaction.respond([{ name: "Error loading tags", value: "" }]);
}
}, async autocomplete(interaction: AutocompleteInteraction) {
const focusedValue = interaction.options.getFocused();
try {
const choices = Docs.filter((tag: TagData) => tag.name.startsWith(focusedValue));
await interaction.respond(
choices.map((choice: TagData) => ({ name: choice.name, value: choice.name }))
);
} catch (error) {
await interaction.respond([{ name: "Error loading tags", value: "" }]);
}
},after code:-
async autocomplete(interaction: AutocompleteInteraction) {
const focusedValue = interaction.options.getFocused(true);
switch (focusedValue.name) {
case "tag":
try {
const choices = Docs.filter((tag: TagData) => tag.name.startsWith(focusedValue.name));
await interaction.respond(
choices.map((choice: TagData) => ({ name: choice.name, value: choice.name }))
);
} catch (error) {
await interaction.respond([{ name: "Error loading tags", value: "" }]);
}
break;
case "hidden":
const choices = ["True", "False"];
await interaction.respond(
choices.map((choice) => ({ name: choice, value: choice }))
);
break;
default:
break;
}
}, async autocomplete(interaction: AutocompleteInteraction) {
const focusedValue = interaction.options.getFocused(true);
switch (focusedValue.name) {
case "tag":
try {
const choices = Docs.filter((tag: TagData) => tag.name.startsWith(focusedValue.name));
await interaction.respond(
choices.map((choice: TagData) => ({ name: choice.name, value: choice.name }))
);
} catch (error) {
await interaction.respond([{ name: "Error loading tags", value: "" }]);
}
break;
case "hidden":
const choices = ["True", "False"];
await interaction.respond(
choices.map((choice) => ({ name: choice, value: choice }))
);
break;
default:
break;
}
},the autocomplete option named tag does not show any options, it used to show earlier but then i added the hidden option and a switch statement then it stopped working