This commit is contained in:
parent
282524f425
commit
990061c6a7
18
src/commands/Community/teste.js
Normal file
18
src/commands/Community/teste.js
Normal 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}`);
|
||||||
|
},
|
||||||
|
};
|
||||||
36
src/events/handlers/teste.js
Normal file
36
src/events/handlers/teste.js
Normal 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([]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
};
|
||||||
Loading…
x
Reference in New Issue
Block a user