import { Autocomplete, Slash, execute } from 'sunar';
import { ApplicationCommandOptionType } from 'discord.js';
const slash = new Slash({
name: 'eat',
description: 'Eat a fruit',
options: [
{
name: 'fruit',
description: 'Select the fruit',
type: ApplicationCommandOptionType.String,
autocomplete: true,
required: true,
},
],
});
execute(slash, (interaction) => {
const fruit = interaction.options.getString('fruit', true);
interaction.reply({ content: `You ate the **${fruit}**.` });
});
const autocomplete = new Autocomplete({
name: 'fruit',
commandName: 'eat', // optional
});
execute(autocomplete, (interaction, option) => {
const data = [
{ name: 'Apple', value: 'apple' },
{ name: 'Kiwi', value: 'kiwi' },
{ name: 'Watermelon', value: 'watermelon' },
{ name: 'Banana', value: 'banana' },
{ name: 'Strawberry', value: 'strawberry' },
];
const results = data.filter((e) =>
e.name.toLowerCase().includes(option.value.toLowerCase())
);
interaction.respond(results);
});
export { slash, autocomplete };