diff --git a/src/commands/Community/teste.js b/src/commands/Community/teste.js new file mode 100644 index 0000000..3dde8e7 --- /dev/null +++ b/src/commands/Community/teste.js @@ -0,0 +1,18 @@ +// comandos/add.js +const { SlashCommandBuilder } = require('discord.js'); + +module.exports = { + data: new SlashCommandBuilder() + .setName('wdd') + .setDescription('Adiciona o servidor à base de dados.') + .addStringOption(option => + option.setName('nome') + .setDescription('Escolhe uma opção') + .setRequired(true) + .setAutocomplete(true) // ATENÇÃO AQUI + ), + async execute(interaction) { + const nome = interaction.options.getString('nome'); + await interaction.reply(`Selecionaste: ${nome}`); + }, +}; \ No newline at end of file diff --git a/src/events/handlers/teste.js b/src/events/handlers/teste.js new file mode 100644 index 0000000..bf03416 --- /dev/null +++ b/src/events/handlers/teste.js @@ -0,0 +1,36 @@ +// events/interactionCreate.js +const conn = require('../../../database/db'); // Ajusta o caminho + +module.exports = { + name: 'interactionCreate', + async execute(interaction, client) { + if (interaction.isChatInputCommand()) { + const command = client.commands.get(interaction.commandName); + if (!command) return; + await command.execute(interaction, client); + } + + // AUTOCOMPLETE + if (interaction.isAutocomplete()) { + const focusedValue = interaction.options.getFocused(); + if (interaction.commandName === 'add' && interaction.options.getSubcommand(false) === null) { + try { + const [rows] = await conn.execute( + 'SELECT nome FROM choices WHERE nome LIKE ? LIMIT 25', + [`%${focusedValue}%`] + ); + + const suggestions = rows.map(row => ({ + name: row.nome, + value: row.value, // ou um ID se preferires + })); + + await interaction.respond(suggestions); + } catch (err) { + console.error('Erro ao buscar sugestões:', err); + await interaction.respond([]); + } + } + } + }, +}; \ No newline at end of file