const client = require("../index"); const { MessageEmbed,MessageButton, TextInputComponent, MessageSelectMenu, MessageActionRow, Modal } = require("discord.js"); client.on("interactionCreate", async (interaction) => { // ———————————————[Slash Commands]——————————————— if (interaction.isCommand()) { await interaction.deferReply({ ephemeral: false }).catch(() => {}); const cmd = client.slashCommands.get(interaction.commandName); if (!cmd) return interaction.followUp({ content: "C'è stato un errore" }); const args = []; for (let option of interaction.options.data) { if (option.type === "SUB_COMMAND") { if (option.name) args.push(option.name); option.options?.forEach((x) => { if (x.value) args.push(x.value); }); } else if (option.value) args.push(option.value); } interaction.member = interaction.guild.members.cache.get( interaction.user.id ); cmd.run(client, interaction, args); } // ———————————————[Buttons]——————————————— if (interaction.isButton()) { } // ———————————————[Select Menu]——————————————— if (interaction.isSelectMenu()) { } // ———————————————[Context Menu]——————————————— if (interaction.isContextMenu()) { await interaction.deferReply({ ephemeral: false }); const command = client.slashCommands.get(interaction.commandName); if (command) command.run(client, interaction); } }) const PartnerSetup = require('../database/schemas/partnerSetup'); client.on('interactionCreate', async interaction => { try { if (interaction.isCommand()) { const command = client.commands.get(interaction.commandName); if (!command) return; try { await command.run(client, interaction); } catch (error) { console.error('Error executing command:', error); if (!interaction.replied && !interaction.deferred) { await interaction.reply({ content: 'There was an error executing this command!', ephemeral: true }); } } } if (interaction.isSelectMenu()) { if (interaction.customId === 'select-partner-channel') { const channelId = interaction.values[0]; const embed = new MessageEmbed() .setTitle('Setup Partner') .setDescription('Select the roles that can manage partnerships.') .setColor('BLUE'); const roles = interaction.guild.roles.cache; const options = roles.map(role => ({ label: role.name, value: role.id })); const row = new MessageActionRow() .addComponents( new MessageSelectMenu() .setCustomId('select-partner-roles') .setPlaceholder('Select roles') .setMinValues(1) .setMaxValues(roles.size) .addOptions(options) ); await interaction.update({ embeds: [embed], components: [row] }); const existingSetup = await PartnerSetup.findOne({ guildId: interaction.guildId }); if (existingSetup) { existingSetup.partnerChannelId = channelId; await existingSetup.save(); } else { await PartnerSetup.create({ guildId: interaction.guildId, partnerChannelId: channelId, partnerRoles: [] }); } } if (interaction.customId === 'select-partner-roles') { const roleIds = interaction.values; const embed = new MessageEmbed() .setTitle('Setup Complete') .setDescription('You have completed the initial setup!') .setColor('GREEN'); await interaction.update({ embeds: [embed], components: [] }); const setup = await PartnerSetup.findOne({ guildId: interaction.guildId }); setup.partnerRoles = roleIds; await setup.save(); } } if (interaction.isModalSubmit()) { if (interaction.customId === 'partnership-modal') { const description = interaction.fields.getTextInputValue('description'); const setup = await PartnerSetup.findOne({ guildId: interaction.guildId }); if (!setup) { if (!interaction.replied && !interaction.deferred) { return await interaction.reply({ content: 'Partner setup not found. Please run /setup-partner first.', ephemeral: true }); } } const channel = interaction.guild.channels.cache.get(setup.partnerChannelId); if (!channel) { if (!interaction.replied && !interaction.deferred) { return await interaction.reply({ content: 'Partner channel not found. Please run /setup-partner again.', ephemeral: true }); } } const embed = new MessageEmbed() .setTitle('New Partnership') .setDescription(description) .setColor('BLUE') .addField('Author', interaction.user.username) .addField('Server', interaction.guild.name) .addField('Manager', interaction.member.user.username); await channel.send({ embeds: [embed] }); if (!interaction.replied && !interaction.deferred) { await interaction.reply({ content: 'Partnership details have been sent!', ephemeral: true }); } } } } catch (error) { console.error('Error handling interaction:', error); if (!interaction.replied && !interaction.deferred) { await interaction.reply({ content: 'There was an error handling this interaction.', ephemeral: true }); } } });