auto complete #77
-
Is it possible to do auto complete on an option and if so How would I set it up using this , as I know this template works slightly different than the discord docs |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments 11 replies
-
I've been working on it and thought about making a pull request, but I didn't because the code is probably not very optimal. Here's what I modified:
if (interaction.isChatInputCommand() || interaction.isContextMenuCommand()) {
const slashCommand = client.slashCommands.get(interaction.commandName);
if (!slashCommand) return;
const authenticatedCMDOptions = await commandOptionsProcessor(client, interaction, slashCommand, true, "SlashCommand");
if (authenticatedCMDOptions) return await slashCommand.run(client, interaction);
} else if (interaction.isAutocomplete()) {
const command = interaction.client.slashCommands.get(interaction.commandName);
if (!command) return;
try {
await command.autocomplete(client, interaction);
} catch (error) {
console.error(error);
}
}
const { ApplicationCommandType, ApplicationCommandOptionType } = require("discord.js");
module.exports = {
name: "name",
description: "blah blah",
type: ApplicationCommandType.ChatInput,
options: [
{
name: 'search',
description: 'Search for a topic',
type: ApplicationCommandOptionType.STRING,
required: true,
autocomplete: true
}
],
run: async (client, interaction) => {
interaction.reply("whatever")
},
async autocomplete(client, interaction) {
const focusedValue = interaction.options.getFocused();
const choices = ['Popular Topics: Threads', 'Sharding: Getting started', 'Library: Voice Connections', 'Interactions: Replying to slash commands', 'Popular Topics: Embed preview'];
const filtered = choices.filter(choice => choice.startsWith(focusedValue));
await interaction.respond(
filtered.map(choice => ({ name: choice, value: choice })),
);
} |
Beta Was this translation helpful? Give feedback.
-
"C:\Program Files\nodejs\node.exe" D:\BOTS\activmod-v7\bot.js SyntaxError: Unexpected identifier SyntaxError: Unexpected identifier |
Beta Was this translation helpful? Give feedback.
-
Finally available in latest version |
Beta Was this translation helpful? Give feedback.
Finally available in latest version