26 lines
898 B
JavaScript
26 lines
898 B
JavaScript
// Autocomplete for ban.js list option
|
|
const colors = require('colors');
|
|
|
|
module.exports = async (interaction, db, client) => {
|
|
if (interaction.commandName !== 'ban') return;
|
|
|
|
const focusedOption = interaction.options.getFocused(true);
|
|
if (focusedOption.name !== 'list') return;
|
|
|
|
const query = focusedOption.value;
|
|
|
|
try {
|
|
db.all(`SELECT id, name FROM lists WHERE id IN (${Array(listIds.length).fill('?').join(',')}) AND name LIKE ? LIMIT 25`, [...listIds, `%${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 ban command:`, error);
|
|
await interaction.respond([]);
|
|
}
|
|
}; |