const { SlashCommandBuilder, EmbedBuilder, ModalBuilder, TextInputBuilder, TextInputStyle, ActionRowBuilder } = require('discord.js'); const config = require('./config.js'); const { roleID, anonChannelID } = config; module.exports = { data: new SlashCommandBuilder() .setName('anon') .setDescription('Invia un messaggio anonimo tramite un modulo'), async execute(interaction) { // Controlla se l'utente ha il ruolo richiesto if (!interaction.member.roles.cache.has(roleID)) { return interaction.reply({ content: 'Non hai il permesso di eseguire questo comando!', ephemeral: true }); } // Crea un modulo per inserire il messaggio anonimo const modal = new ModalBuilder() .setCustomId('anonModal') .setTitle('Invia un messaggio anonimo'); const messageInput = new TextInputBuilder() .setCustomId('anonMessage') .setLabel('Inserisci il tuo messaggio anonimo') .setStyle(TextInputStyle.Paragraph) .setRequired(true); const firstActionRow = new ActionRowBuilder().addComponents(messageInput); modal.addComponents(firstActionRow); // Mostra il modulo all'utente await interaction.showModal(modal); }, async handleModalSubmit(interaction) { if (interaction.customId === 'anonModal') { const messaggio = interaction.fields.getTextInputValue('anonMessage'); try { // Invia il messaggio anonimo nel canale designato const anonChannel = await interaction.guild.channels.fetch(anonChannelID); const embed = new EmbedBuilder() .setTitle('Messaggio Anonimo') .setDescription(messaggio) .setTimestamp() .setFooter({ text: 'L U N A R®' }) .setColor(`#${Math.floor(Math.random() * 16777215).toString(16).padStart(6, '0')}`); await anonChannel.send({ embeds: [embed] }); // Rispondi all'utente await interaction.reply({ content: 'Il tuo messaggio anonimo è stato inviato con successo!', ephemeral: true }); } catch (error) { console.error('Errore durante l\'invio del messaggio anonimo:', error); if (!interaction.replied) { await interaction.reply({ content: 'Errore durante l\'invio del messaggio anonimo.', ephemeral: true }); } } } } };