const { Client, GatewayIntentBits, ActionRowBuilder, StringSelectMenuBuilder, TextInputBuilder, TextInputStyle, ModalBuilder, InteractionType, EmbedBuilder, ChannelType } = require('discord.js'); const config = require('./config.json'); require('dotenv').config(); const client = new Client({ intents: [GatewayIntentBits.Guilds, GatewayIntentBits.GuildMessages, GatewayIntentBits.MessageContent] }); client.once('ready', () => { console.log(`Logged in as ${client.user.tag}!`); const channelId = config.logChannel; // Frissítsd a channelId-t az adott csatorna ID-ra const channel = client.channels.cache.get(channelId); if (!channel) { console.error(`Channel with ID ${channelId} not found.`); return; } const embed = new EmbedBuilder() .setTitle('Setup Ticket System') .setDescription('Choose a team to contact from the dropdown below.') .setColor(0x00FFFF); const row = new ActionRowBuilder() .addComponents( new StringSelectMenuBuilder() .setCustomId('support_team') .setPlaceholder('Pick who do you call for support') .addOptions([ { label: 'Punishment team', value: 'punishment', }, { label: 'Recruitment team', value: 'recruitment', }, { label: 'Ownership team', value: 'ownership', }, { label: 'General Support', value: 'general', }, { label: 'Reports', value: 'reports', }, ]), ); channel.send({ embeds: [embed], components: [row] }) .catch(error => { console.error('Error sending setup message:', error); }); }); client.on('interactionCreate', async interaction => { if (interaction.isStringSelectMenu() && interaction.customId === 'support_team') { const team = interaction.values[0]; if (interaction.replied || interaction.deferred) { console.log('Interaction already replied or deferred.'); return; } try { await interaction.deferUpdate(); const modal = new ModalBuilder() .setCustomId(`ticket_${team}`) .setTitle('Create Ticket') .addComponents( new ActionRowBuilder().addComponents( new TextInputBuilder() .setCustomId('reason') .setLabel('Reason for creating this ticket') .setStyle(TextInputStyle.Paragraph) .setRequired(true) ) ); await interaction.showModal(modal); } catch (error) { console.error('Error showing modal:', error); if (!interaction.replied) { await interaction.reply({ content: 'There was an error processing your request.', ephemeral: true }); } } } else if (interaction.isModalSubmit() && interaction.customId.startsWith('ticket_')) { const team = interaction.customId.split('_')[1]; const reason = interaction.fields.getTextInputValue('reason'); const ticketCategoryId = config.ticketCategory; const logChannelId = config.logChannel; const guild = interaction.guild; const category = guild.channels.cache.get(ticketCategoryId); const logChannel = client.channels.cache.get(logChannelId); if (!category) { console.error(`Category with ID ${ticketCategoryId} not found.`); return; } if (!logChannel) { console.error(`Log channel with ID ${logChannelId} not found.`); return; } try { const ticketChannel = await guild.channels.create({ name: `ticket-${Date.now()}`, type: ChannelType.GuildText, // Frissített típus parent: category, permissionOverwrites: [ { id: guild.roles.everyone, deny: ['ViewChannel'], }, { id: config.roles.supportTeams[team], allow: ['ViewChannel', 'SendMessages'], }, { id: interaction.user.id, allow: ['ViewChannel', 'SendMessages'], }, ], }); const embed = new EmbedBuilder() .setTitle('Ticket Created') .setDescription(`Reason: ${reason}`) .setColor(0x00FF00); await ticketChannel.send({ embeds: [embed] }); await interaction.reply({ content: 'Your ticket has been created.', ephemeral: true }); await logChannel.send({ content: `A new ticket has been created in ${ticketChannel}. Reason: ${reason}` }); } catch (error) { console.error('Error creating ticket:', error); if (!interaction.replied) { await interaction.reply({ content: 'There was an error processing your request.', ephemeral: true }); } } } }); client.login(process.env.TOKEN);