This commit is contained in:
Bxio 2025-04-05 11:03:12 +01:00
parent 282524f425
commit 990061c6a7
2 changed files with 54 additions and 0 deletions

View File

@ -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}`);
},
};

View File

@ -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([]);
}
}
}
},
};