27 lines
946 B
JavaScript
27 lines
946 B
JavaScript
// Autocomplete handler for /list delete and /list transfer commands
|
|
const colors = require('colors');
|
|
|
|
module.exports = async (interaction, db, client) => {
|
|
if (interaction.commandName !== 'list') return;
|
|
|
|
const focusedOption = interaction.options.getFocused(true);
|
|
if (focusedOption.name !== 'list') return;
|
|
|
|
const query = focusedOption.value || "";
|
|
|
|
try {
|
|
// Fetch lists owned by the user
|
|
db.all(`SELECT id, name FROM lists WHERE owner_id = ? AND name LIKE ? LIMIT 25`, [interaction.user.id, `%${query}%`], async (err, lists) => {
|
|
|
|
const choices = lists.map(list => ({
|
|
name: list.name,
|
|
value: list.id.toString()
|
|
}));
|
|
|
|
await interaction.respond(choices);
|
|
});
|
|
} catch (error) {
|
|
console.error(`${colors.red('[ERROR]')} Error handling autocomplete for list command:`, error);
|
|
await interaction.respond([]);
|
|
}
|
|
}; |