Advertisement
DeveloperADMIN

Tickets Report ( Discord )

Apr 8th, 2025 (edited)
378
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
JavaScript 13.53 KB | Source Code | 0 0
  1. const { Client, GatewayIntentBits, EmbedBuilder, ModalBuilder, TextInputBuilder, TextInputStyle, ActionRowBuilder, ButtonBuilder, ButtonStyle } = require('discord.js');
  2.  
  3. const bot = new Client({
  4.     intents: [
  5.         GatewayIntentBits.Guilds,
  6.         GatewayIntentBits.GuildMessages,
  7.         GatewayIntentBits.MessageContent,
  8.         GatewayIntentBits.GuildMembers
  9.     ]
  10. });
  11. /////////////////////////////////////////////// Setup /////////////////////////////////////////////////
  12.  
  13. const PREFIX = "-"; // البريفكس
  14. const rpi = ''; // id log channel - اي دي اتشانل اللوج
  15. const token = ""; // توكن البوت
  16.  
  17. ///////////////////////////////////////////////////////////////////////////////////////////////////////
  18. const tic = new Map();
  19. let lang = 'ar';
  20.  
  21. const translations = {
  22.     ar: {
  23.         noTicketId: "لم يتم العثور على رقم التذكرة. الرجاء النقر على الزر لإدخال الرقم يدويًا.",
  24.         enterTicketNumber: "إدخال رقم التذكرة",
  25.         closeTicket: "إغلاق التذكرة",
  26.         fillDetails: "لاستكمال الإجراءات، يرجى ملء البيانات التالية:\n- بيانات المسؤول\n- بيانات التذكرة",
  27.         ticketNumber: "رقم التذكرة:",
  28.         ticketLink: "رابط التذكرة:",
  29.         adminData: "بيانات المسؤول",
  30.         ticketData: "بيانات التذكرة",
  31.         savedTicketNum: (num) => `تم حفظ رقم التذكرة: ${num}`,
  32.         adminModalTitle: "بيانات المسؤول",
  33.         adminLabel: "اسم المسؤول عن التذكرة (اليوزر أو الآيدي)",
  34.         statusLabel: "حالة التذكرة: (مغلق / مفتوح / قيد المعالجة)",
  35.         ticketModalTitle: "تقرير التذكرة",
  36.         reasonLabel: "سبب فتح التذكرة؟",
  37.         actionsTakenLabel: "ما هي الإجراءات المتخذة؟",
  38.         contactedLabel: "هل تم التواصل مع المستخدم؟ (نعم/لا)",
  39.         resolvedLabel: "هل تم حل المشكلة؟ (نعم/لا)",
  40.         notesLabel: "ملاحظات إضافية (اختياري)",
  41.         savedAdmin: "تم حفظ بيانات المسؤول.",
  42.         reportTitle: "تقرير التذكرة",
  43.         doneSend: "**تم الارسال**",
  44.         noData: "حدث خطاء",
  45.         langChanged: "تم تغيير اللغة إلى العربية.",
  46.         staffticket: "المسؤول عن التذكرة",
  47.         ticketst: "حالة التذكرة",
  48.         adnote: "ملاحظات إضافية",
  49.         addnote: "لا يوجد"
  50.        
  51.     },
  52.     en: {
  53.         noTicketId: "Ticket number not found. Please click the button to enter it manually.",
  54.         enterTicketNumber: "Enter Ticket Number",
  55.         closeTicket: "Close Ticket",
  56.         fillDetails: "To proceed, please fill in the following:\n- Admin Info\n- Ticket Info",
  57.         ticketNumber: "Ticket Number:",
  58.         ticketLink: "Ticket Link:",
  59.         adminData: "Admin Info",
  60.         ticketData: "Ticket Info",
  61.         savedTicketNum: (num) => `Ticket number saved: ${num}`,
  62.         adminModalTitle: "Admin Info",
  63.         adminLabel: "Admin name (username or ID)",
  64.         statusLabel: "Ticket Status: (Closed / Open / Processing)",
  65.         ticketModalTitle: "Ticket Report",
  66.         reasonLabel: "Why was the ticket opened?",
  67.         actionsTakenLabel: "What actions were taken?",
  68.         contactedLabel: "Was the user contacted? (Yes/No)",
  69.         resolvedLabel: "Was the issue resolved? (Yes/No)",
  70.         notesLabel: "Additional notes (optional)",
  71.         savedAdmin: "Admin data saved.",
  72.         reportTitle: "Ticket Report",
  73.         doneSend: "**Done Send**",
  74.         noData: "Error: No data saved",
  75.         langChanged: "Language changed to English.",
  76.         staffticket: "Ticket Staff",
  77.         ticketst: "Ticket status",
  78.         adnote: "Additional notes",
  79.         addnote: "No Notes"
  80.     }
  81. };
  82.  
  83. let t = translations[lang];
  84.  
  85. bot.once('ready', () => {
  86.     console.log(`Done ${bot.user.tag}`);
  87. });
  88.  
  89. bot.on('messageCreate', async (message) => {
  90.     if (message.author.bot || !message.content.startsWith(PREFIX)) return;
  91.  
  92.     const args = message.content.slice(PREFIX.length).trim().split(/ +/);
  93.     const command = args.shift().toLowerCase();
  94.  
  95.     if (command === 'lang') {
  96.         if (args[0] === 'ar' || args[0] === 'en') {
  97.             lang = args[0];
  98.             t = translations[lang];
  99.             await message.reply(t.langChanged);
  100.         } else {
  101.             await message.reply("Usage: -lang [ar/en]");
  102.         }
  103.         return;
  104.     }
  105.  
  106.     if (command === 'tc') {
  107.         const channel = message.channel;
  108.         const ticid = channel.name.split('-').pop();
  109.  
  110.         if (!ticid || isNaN(ticid)) {
  111.             const button = new ButtonBuilder()
  112.                 .setCustomId('req_ticket_num')
  113.                 .setLabel(t.enterTicketNumber)
  114.                 .setStyle(ButtonStyle.Primary);
  115.  
  116.             const row = new ActionRowBuilder().addComponents(button);
  117.  
  118.             await message.reply({
  119.                 content: t.noTicketId,
  120.                 components: [row]
  121.             });
  122.             return;
  123.         }
  124.  
  125.         tic.set(channel.id, { ticid });
  126.  
  127.         const confirmEmbed = new EmbedBuilder()
  128.             .setTitle(t.closeTicket)
  129.             .setDescription(t.fillDetails)
  130.             .addFields(
  131.                 { name: t.ticketNumber, value: ticid, inline: true },
  132.                 { name: t.ticketLink, value: `<#${channel.id}>`, inline: true }
  133.             )
  134.             .setColor(0x29D2D2);
  135.  
  136.         const adminButton = new ButtonBuilder()
  137.             .setCustomId('admin_data')
  138.             .setLabel(t.adminData)
  139.             .setStyle(ButtonStyle.Primary);
  140.  
  141.         const ticketButton = new ButtonBuilder()
  142.             .setCustomId('tic_data')
  143.             .setLabel(t.ticketData)
  144.             .setStyle(ButtonStyle.Secondary);
  145.  
  146.         const row = new ActionRowBuilder().addComponents(adminButton, ticketButton);
  147.  
  148.         await message.channel.send({ embeds: [confirmEmbed], components: [row] });
  149.     }
  150. });
  151.  
  152. bot.on('interactionCreate', async (interaction) => {
  153.     if (interaction.isButton() && interaction.customId === 'req_ticket_num') {
  154.         const modal = new ModalBuilder()
  155.             .setCustomId('ticket_num_modal')
  156.             .setTitle(t.enterTicketNumber);
  157.  
  158.         const ticketNumberInput = new TextInputBuilder()
  159.             .setCustomId('ticket_num')
  160.             .setLabel(t.ticketNumber)
  161.             .setStyle(TextInputStyle.Short)
  162.             .setRequired(true);
  163.  
  164.         modal.addComponents(new ActionRowBuilder().addComponents(ticketNumberInput));
  165.  
  166.         await interaction.showModal(modal);
  167.         return;
  168.     }
  169.  
  170.     if (interaction.isModalSubmit() && interaction.customId === 'ticket_num_modal') {
  171.         const ticketNum = interaction.fields.getTextInputValue('ticket_num');
  172.         const channelID = interaction.channel.id;
  173.  
  174.         tic.set(channelID, { ticid: ticketNum });
  175.  
  176.         await interaction.reply({ content: t.savedTicketNum(ticketNum), ephemeral: true });
  177.  
  178.         const confirmEmbed = new EmbedBuilder()
  179.             .setTitle(t.closeTicket)
  180.             .setDescription(t.fillDetails)
  181.             .addFields(
  182.                 { name: t.ticketNumber, value: ticketNum, inline: true },
  183.                 { name: t.ticketLink, value: `<#${channelID}>`, inline: true }
  184.             )
  185.             .setColor(0x29D2D2);
  186.  
  187.         const adminButton = new ButtonBuilder()
  188.             .setCustomId('admin_data')
  189.             .setLabel(t.adminData)
  190.             .setStyle(ButtonStyle.Primary);
  191.  
  192.         const ticketButton = new ButtonBuilder()
  193.             .setCustomId('tic_data')
  194.             .setLabel(t.ticketData)
  195.             .setStyle(ButtonStyle.Secondary);
  196.  
  197.         await interaction.channel.send({ embeds: [confirmEmbed], components: [new ActionRowBuilder().addComponents(adminButton, ticketButton)] });
  198.     }
  199.  
  200.     if (interaction.isButton() && (interaction.customId === 'admin_data' || interaction.customId === 'tic_data')) {
  201.         const channelID = interaction.channel.id;
  202.         const ticket = tic.get(channelID);
  203.         if (!ticket) return interaction.reply({ content: t.noData, ephemeral: true });
  204.  
  205.         if (interaction.customId === 'admin_data') {
  206.             const modal = new ModalBuilder()
  207.                 .setCustomId('ad_rp')
  208.                 .setTitle(t.adminModalTitle);
  209.  
  210.             const adminInput = new TextInputBuilder()
  211.                 .setCustomId('admin')
  212.                 .setLabel(t.adminLabel)
  213.                 .setStyle(TextInputStyle.Short)
  214.                 .setRequired(true);
  215.  
  216.             const statusInput = new TextInputBuilder()
  217.                 .setCustomId('status')
  218.                 .setLabel(t.statusLabel)
  219.                 .setStyle(TextInputStyle.Short)
  220.                 .setRequired(true);
  221.  
  222.             modal.addComponents(
  223.                 new ActionRowBuilder().addComponents(adminInput),
  224.                 new ActionRowBuilder().addComponents(statusInput)
  225.             );
  226.  
  227.             await interaction.showModal(modal);
  228.         } else if (interaction.customId === 'tic_data') {
  229.             const modal = new ModalBuilder()
  230.                 .setCustomId('tic_rp')
  231.                 .setTitle(t.ticketModalTitle);
  232.  
  233.             const reasonInput = new TextInputBuilder()
  234.                 .setCustomId('reason')
  235.                 .setLabel(t.reasonLabel)
  236.                 .setStyle(TextInputStyle.Short)
  237.                 .setRequired(true);
  238.  
  239.             const actionInput = new TextInputBuilder()
  240.                 .setCustomId('actions_taken')
  241.                 .setLabel(t.actionsTakenLabel)
  242.                 .setStyle(TextInputStyle.Paragraph)
  243.                 .setRequired(true);
  244.  
  245.             const contactInput = new TextInputBuilder()
  246.                 .setCustomId('contacted')
  247.                 .setLabel(t.contactedLabel)
  248.                 .setStyle(TextInputStyle.Short)
  249.                 .setRequired(true);
  250.  
  251.             const resolvedInput = new TextInputBuilder()
  252.                 .setCustomId('resolved')
  253.                 .setLabel(t.resolvedLabel)
  254.                 .setStyle(TextInputStyle.Short)
  255.                 .setRequired(true);
  256.  
  257.             const notesInput = new TextInputBuilder()
  258.                 .setCustomId('notes')
  259.                 .setLabel(t.notesLabel)
  260.                 .setStyle(TextInputStyle.Paragraph)
  261.                 .setRequired(false);
  262.  
  263.             modal.addComponents(
  264.                 new ActionRowBuilder().addComponents(reasonInput),
  265.                 new ActionRowBuilder().addComponents(actionInput),
  266.                 new ActionRowBuilder().addComponents(contactInput),
  267.                 new ActionRowBuilder().addComponents(resolvedInput),
  268.                 new ActionRowBuilder().addComponents(notesInput)
  269.             );
  270.  
  271.             await interaction.showModal(modal);
  272.         }
  273.     }
  274.  
  275.     if (interaction.isModalSubmit() && (interaction.customId === 'ad_rp' || interaction.customId === 'tic_rp')) {
  276.         const channelID = interaction.channel.id;
  277.         const ticket = tic.get(channelID);
  278.         if (!ticket) return interaction.reply({ content: t.noData, ephemeral: true });
  279.  
  280.         if (interaction.customId === 'ad_rp') {
  281.             const admin = interaction.fields.getTextInputValue('admin');
  282.             const status = interaction.fields.getTextInputValue('status');
  283.  
  284.             tic.set(channelID, { ...ticket, admin, status });
  285.  
  286.             await interaction.reply({ content: t.savedAdmin, ephemeral: true });
  287.         } else if (interaction.customId === 'tic_rp') {
  288.             const reason = interaction.fields.getTextInputValue('reason');
  289.             const actionsTaken = interaction.fields.getTextInputValue('actions_taken');
  290.             const contacted = interaction.fields.getTextInputValue('contacted');
  291.             const resolved = interaction.fields.getTextInputValue('resolved');
  292.             const notes = interaction.fields.getTextInputValue('notes') || t.addnote;
  293.  
  294.             const staffMember = interaction.user;
  295.  
  296.             const finalData = { ...tic.get(channelID), reason, actionsTaken, contacted, resolved, notes };
  297.  
  298.             const reportEmbed = new EmbedBuilder()
  299.                 .setTitle(t.reportTitle)
  300.                 .setColor(0x29D2D2)
  301.                 .addFields(
  302.                     { name: t.ticketNumber, value: finalData.ticid, inline: true },
  303.                     { name: t.ticketLink, value: `<#${channelID}>`, inline: true },
  304.                     { name: t.staffticket, value: finalData.admin, inline: true },
  305.                     { name: t.ticketst, value: finalData.status, inline: true },
  306.                     { name: t.reasonLabel, value: finalData.reason, inline: false },
  307.                     { name: t.actionsTakenLabel, value: finalData.actionsTaken, inline: false },
  308.                     { name: t.contactedLabel, value: finalData.contacted, inline: true },
  309.                     { name: t.resolvedLabel, value: finalData.resolved, inline: true },
  310.                     { name: t.adnote, value: finalData.notes, inline: false }
  311.                 )
  312.                 .setFooter({ text: `${staffMember.tag}`, iconURL: staffMember.displayAvatarURL() });
  313.  
  314.             const reportChannel = await bot.channels.fetch(rpi);
  315.             if (reportChannel.isTextBased()) {
  316.                 await reportChannel.send({ embeds: [reportEmbed] });
  317.             }
  318.  
  319.             tic.delete(channelID);
  320.  
  321.             await interaction.reply({ content: t.doneSend, ephemeral: true });
  322.         }
  323.     }
  324. });
  325.  
  326. bot.login(token);
  327.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement