41 lines
1.3 KiB
JavaScript
41 lines
1.3 KiB
JavaScript
// events/interactionCreate.js
|
|
const { InteractionContextType, PermissionFlagsBits, SlashCommandBuilder, MessageFlags } = require('discord.js');
|
|
const conn = require('../../../database/db'); // Ajusta o caminho
|
|
|
|
|
|
module.exports = {
|
|
name: 'interactionCreate',
|
|
async execute(interaction, client) {
|
|
|
|
|
|
if (interaction.isAutocomplete()) {
|
|
const focusedValue = interaction.options.getFocused(true);
|
|
|
|
if (interaction.commandName === 'wdd') {
|
|
console.error(focusedValue);
|
|
if (focusedValue.name == 'nome'){
|
|
|
|
try {
|
|
|
|
const [rows] = await conn.execute(
|
|
'SELECT name,value FROM choices LIMIT 25',
|
|
[`%${focusedValue}%`]
|
|
);
|
|
|
|
const suggestions = rows.map(row => ({
|
|
name: row.name,
|
|
value: row.value,
|
|
}));
|
|
|
|
await interaction.respond(suggestions);
|
|
} catch (err) {
|
|
console.error('Erro ao buscar sugestões:', err);
|
|
await interaction.respond([]);
|
|
}
|
|
}
|
|
|
|
|
|
}
|
|
}
|
|
},
|
|
}; |