AutoComplete Problem

before:-
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
2 Replies
d.js toolkit
d.js toolkit8mo ago
- What's your exact discord.js npm list discord.js and node node -v version? - Not a discord.js issue? Check out #other-js-ts. - Consider reading #how-to-get-help to improve your question! - Explain what exactly your issue is. - Post the full error stack trace, not just the top part! - Show your code! - Issue solved? Press the button! - Marked as resolved by OP
Resident Of Prey
Resident Of PreyOP8mo ago
data: new SlashCommandBuilder()
.setName("tag")
.setDescription("Search the documentation for small pieces of info")
.addStringOption(option => option.setName("tag").setDescription("name of the tag to search for").setRequired(true).setAutocomplete(true))
.addStringOption(option => option.setName("hidden").setDescription("should the response be hidden?").setRequired(false).setAutocomplete(true))
data: new SlashCommandBuilder()
.setName("tag")
.setDescription("Search the documentation for small pieces of info")
.addStringOption(option => option.setName("tag").setDescription("name of the tag to search for").setRequired(true).setAutocomplete(true))
.addStringOption(option => option.setName("hidden").setDescription("should the response be hidden?").setRequired(false).setAutocomplete(true))
for a moment i forgot that BooleanOption even exists thanks anyways
Want results from more Discord servers?
Add your server