33 lines
1.2 KiB
JavaScript
33 lines
1.2 KiB
JavaScript
// Autocomplete for lists on /guild subcommands
|
|
const colors = require('colors');
|
|
|
|
module.exports = async (interaction, db, client) => {
|
|
if (interaction.commandName !== 'guild') return;
|
|
|
|
const focusedOption = interaction.options.getFocused(true);
|
|
if (focusedOption.name !== 'list_id') return;
|
|
|
|
const query = focusedOption.value || "";
|
|
|
|
try {
|
|
// Fetch lists joined by the guild
|
|
db.all(`SELECT l.id, l.name FROM lists l
|
|
JOIN guilds gl ON l.id = gl.list_id
|
|
WHERE gl.guild_id = ? AND l.name LIKE ? LIMIT 25`,
|
|
[interaction.guild.id, `%${query}%`], async (err, lists) => {
|
|
if (err) {
|
|
console.error(`${colors.red('[ERROR]')} Error fetching lists for autocomplete:`, err);
|
|
return await interaction.respond([]);
|
|
}
|
|
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 guild command:`, error);
|
|
await interaction.respond([]);
|
|
}
|
|
}; |