Advertisement
W4jebka

Ticket

Jan 22nd, 2022
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. -------------------------------------COMMAND/TICKET.JS---------------------------------------------------
  2. const { MessageEmbed, MessageActionRow, MessageButton} = require("discord.js");
  3.  
  4. module.exports = {
  5.     name: "ticket",
  6.     aliases: ['p'],
  7.     permissions : ["ADMINISTRATOR *"],
  8.     /**
  9.      *
  10.      * @param {Client} client
  11.      * @param {Message} message
  12.      * @param {String[]} args
  13.      */
  14.     run: async (client, message, args) => {
  15.         const embed = new MessageEmbed()
  16.                 .setColor('YELLOW')
  17.                 .setAuthor({
  18.                     name: 'Wiesmc.pl| Ticket',
  19.                     iconURL: `https://cdn.discordapp.com/icons/778969600591134740/b581f0c2573cfdab3ceab45ba0545c78.webp`,
  20.                   })
  21.                 .setDescription("Aby utowrzyć ticket w celu pomocy naciśnij w przycisk!")
  22.                 .setThumbnail(`https://cdn.discordapp.com/icons/778969600591134740/b581f0c2573cfdab3ceab45ba0545c78.webp`)
  23.                 .setTitle('Ticket!!!')
  24.                 .setFooter({
  25.                     text: `Wiesmc.pl| 2022`,  
  26.                     iconURL: `https://cdn.discordapp.com/icons/778969600591134740/b581f0c2573cfdab3ceab45ba0545c78.webp`,
  27.                 })
  28.             const newButton = new MessageActionRow().addComponents(
  29.                 new MessageButton()
  30.                     .setCustomId('Ticket')
  31.                     .setLabel('💌Otwórz Ticket!')
  32.                     .setStyle('SUCCESS')
  33.                 //  .setDisabled(true)
  34.             );
  35.        
  36.             message.channel.send({ embeds: [embed], components: [newButton]});
  37.     },
  38. };
  39.  
  40.  
  41.  
  42. -------------------------------------EVENT/TICKET.JS---------------------------------------------------
  43. const { MessageEmbed, MessageActionRow, MessageButton, MessageSelectMenu } = require('discord.js');
  44. const client = require("..");
  45. const hastebin = require('hastebin');
  46.  
  47. client.on('interactionCreate', async interaction => { {
  48.     if (!interaction.isButton()) return;
  49.     if (interaction.customId == "Ticket") {
  50.       if (client.guilds.cache.get(interaction.guildId).channels.cache.find(c => c.topic == interaction.user.id)) {
  51.         return interaction.reply({
  52.           content: 'Ticket został już utworzony !',
  53.           ephemeral: true
  54.         });
  55.       };
  56.  
  57.       interaction.guild.channels.create(`ticket-${interaction.user.username}`, {
  58.         parent: "934383759170629632",
  59.         topic: interaction.user.id,
  60.         permissionOverwrites: [{
  61.             id: interaction.user.id,
  62.             allow: ['SEND_MESSAGES', 'VIEW_CHANNEL'],
  63.           },
  64.           {
  65.             id: "927565458880733335",
  66.             allow: ['SEND_MESSAGES', 'VIEW_CHANNEL'],
  67.           },
  68.           {
  69.             id: interaction.guild.roles.everyone,
  70.             deny: ['VIEW_CHANNEL'],
  71.           },
  72.         ],
  73.         type: 'text',
  74.       }).then(async c => {
  75.         interaction.reply({
  76.           content: `Ticket Został utworzony <#${c.id}>`,
  77.           ephemeral: true
  78.         });
  79.  
  80.         const embed = new MessageEmbed()
  81.           .setColor('YELLOW')
  82.           .setAuthor({
  83.             name: 'Ticket',
  84.             iconURL: `https://cdn.discordapp.com/icons/778969600591134740/b581f0c2573cfdab3ceab45ba0545c78.webp`,
  85.           })
  86.           .setDescription('Wybierz Kategorie ticketu')
  87.           .setFooter({
  88.             text: `Wiesmc.pl| 2022`,  
  89.             iconURL: `https://cdn.discordapp.com/icons/778969600591134740/b581f0c2573cfdab3ceab45ba0545c78.webp`,
  90.         })
  91.           .setTimestamp();
  92.  
  93.         const row = new MessageActionRow()
  94.           .addComponents(
  95.             new MessageSelectMenu()
  96.             .setCustomId('category')
  97.             .setPlaceholder('Wybierz kategorię biletu')
  98.             .addOptions([{
  99.                 label: 'Transakcja',
  100.                 value: 'Transakcja',
  101.                 emoji: '🪙',
  102.               },
  103.               {
  104.                 label: 'Pomoc',
  105.                 value: 'Pomoc',
  106.                 emoji: '🎮',
  107.               },
  108.               {
  109.                 label: 'Konkurs',
  110.                 value: 'Konkurs',
  111.                 emoji: '📔',
  112.               },
  113.             ]),
  114.           );
  115.  
  116.         msg = await c.send({
  117.           content: `<@!${interaction.user.id}>`,
  118.           embeds: [embed],
  119.           components: [row]
  120.         });
  121.  
  122.         const collector = msg.createMessageComponentCollector({
  123.           componentType: 'SELECT_MENU',
  124.           time: 20000
  125.         });
  126.  
  127.         collector.on('collect', i => {
  128.           if (i.user.id === interaction.user.id) {
  129.             if (msg.deletable) {
  130.               msg.delete().then(async () => {
  131.                 const embed = new MessageEmbed()
  132.                   .setColor('YELLOW')
  133.                   .setAuthor({
  134.                     name: 'Ticket',
  135.                     iconURL: `https://cdn.discordapp.com/icons/778969600591134740/b581f0c2573cfdab3ceab45ba0545c78.webp`,
  136.                   })
  137.                   .setDescription(`<@!${interaction.user.id}> Twój Ticket ${i.values[0]}`)
  138.                   .setFooter({
  139.                     text: `Wiesmc.pl| 2022`,  
  140.                     iconURL: `https://cdn.discordapp.com/icons/778969600591134740/b581f0c2573cfdab3ceab45ba0545c78.webp`,
  141.                 })
  142.                   .setTimestamp();
  143.  
  144.                 const row = new MessageActionRow()
  145.                   .addComponents(
  146.                     new MessageButton()
  147.                     .setCustomId('close-ticket')
  148.                     .setLabel('Zamknij bilet')
  149.                     .setEmoji('899745362137477181')
  150.                     .setStyle('DANGER'),
  151.                   );
  152.  
  153.                 const opened = await c.send({
  154.                   content: `<@&927565458880733335>`,
  155.                   embeds: [embed],
  156.                   components: [row]
  157.                 });
  158.  
  159.                 opened.pin().then(() => {
  160.                   opened.channel.bulkDelete(1);
  161.                 });
  162.               });
  163.             };
  164.             if (i.values[0] == 'Transakcja') {
  165.               c.edit({
  166.                 parent: "934383632817213510",
  167.               });
  168.             };
  169.             if (i.values[0] == 'Pomoc') {
  170.               c.edit({
  171.                 parent: "934383704070037584",
  172.               });
  173.             };
  174.             if (i.values[0] == 'Konkurs') {
  175.               c.edit({
  176.                 parent: "934384078554288148",
  177.               });
  178.             };
  179.           };
  180.         });
  181.  
  182.         collector.on('end', collected => {
  183.           if (collected.size < 1) {
  184.             c.send(`Brak wybranych kategorii. Zamknięcie biletu...`).then(() => {
  185.               setTimeout(() => {
  186.                 if (c.deletable) {
  187.                   c.delete();
  188.                 };
  189.               }, 5000);
  190.             });
  191.           };
  192.         });
  193.       });
  194.     };
  195.  
  196.     if (interaction.customId == "close-ticket") {
  197.       const guild = client.guilds.cache.get(interaction.guildId);
  198.       const chan = guild.channels.cache.get(interaction.channelId);
  199.  
  200.       const row = new MessageActionRow()
  201.         .addComponents(
  202.           new MessageButton()
  203.           .setCustomId('confirm-close')
  204.           .setLabel('Zamknij bilet')
  205.           .setStyle('DANGER'),
  206.           new MessageButton()
  207.           .setCustomId('no')
  208.           .setLabel('Anuluj zamknięcie')
  209.           .setStyle('SECONDARY'),
  210.         );
  211.  
  212.       const verif = await interaction.reply({
  213.         content: 'Czy na pewno chcesz zamknąć bilet ?',
  214.         components: [row]
  215.       });
  216.  
  217.       const collector = interaction.channel.createMessageComponentCollector({
  218.         componentType: 'BUTTON',
  219.         time: 10000
  220.       });
  221.  
  222.       collector.on('collect', i => {
  223.         if (i.customId == 'confirm-close') {
  224.           interaction.editReply({
  225.             content: `Bilet zamknięty przez <@!${interaction.user.id}>`,
  226.             components: []
  227.           });
  228.  
  229.           chan.edit({
  230.               name: `closed-${chan.name}`,
  231.               permissionOverwrites: [
  232.                 {
  233.                   id: client.users.cache.get(chan.topic),
  234.                   deny: ['SEND_MESSAGES', 'VIEW_CHANNEL'],
  235.                 },
  236.                 {
  237.                   id: "927565458880733335",
  238.                   allow: ['SEND_MESSAGES', 'VIEW_CHANNEL'],
  239.                 },
  240.                 {
  241.                   id: interaction.guild.roles.everyone,
  242.                   deny: ['VIEW_CHANNEL'],
  243.                 },
  244.               ],
  245.             })
  246.             .then(async () => {
  247.               const embed = new MessageEmbed()
  248.                 .setColor('YELLOW')
  249.                 .setAuthor({
  250.                   name: 'Ticket',
  251.                   iconURL: `https://cdn.discordapp.com/icons/778969600591134740/b581f0c2573cfdab3ceab45ba0545c78.webp`,
  252.                 })
  253.                 .setDescription('```Controla Ticketu```')
  254.                 .setFooter({
  255.                   text: `Wiesmc.pl| 2022`,  
  256.                   iconURL: `https://cdn.discordapp.com/icons/778969600591134740/b581f0c2573cfdab3ceab45ba0545c78.webp`,
  257.               })
  258.                 .setTimestamp();
  259.  
  260.               const row = new MessageActionRow()
  261.                 .addComponents(
  262.                   new MessageButton()
  263.                   .setCustomId('delete-ticket')
  264.                   .setLabel('Usuń bilet')
  265.                   .setEmoji('🗑️')
  266.                   .setStyle('DANGER'),
  267.                 );
  268.  
  269.               chan.send({
  270.                 embeds: [embed],
  271.                 components: [row]
  272.               });
  273.             });
  274.  
  275.           collector.stop();
  276.         };
  277.         if (i.customId == 'no') {
  278.           interaction.editReply({
  279.             content: 'Zamknięcie anulowanego biletu !',
  280.             components: []
  281.           });
  282.           collector.stop();
  283.         };
  284.       });
  285.  
  286.       collector.on('end', (i) => {
  287.         if (i.size < 1) {
  288.           interaction.editReply({
  289.             content: 'Zamknięcie anulowanego biletu !',
  290.             components: []
  291.           });
  292.         };
  293.       });
  294.     };
  295.  
  296.     if (interaction.customId == "delete-ticket") {
  297.       const guild = client.guilds.cache.get(interaction.guildId);
  298.       const chan = guild.channels.cache.get(interaction.channelId);
  299.  
  300.       interaction.reply({
  301.         content: 'Tworzenie kopii zapasowych wiadomości...'
  302.       });
  303.  
  304.       chan.messages.fetch().then(async (messages) => {
  305.         let a = messages.filter(m => m.author.bot !== true).map(m =>
  306.           `${new Date(m.createdTimestamp).toLocaleString('fr-FR')} - ${m.author.username}#${m.author.discriminator}: ${m.attachments.size > 0 ? m.attachments.first().proxyURL : m.content}`
  307.         ).reverse().join('\n');
  308.         if (a.length < 1) a = "Nothing"
  309.         hastebin.createPaste(a, {
  310.             contentType: 'text/plain',
  311.             server: 'https://hastebin.com'
  312.           }, {})
  313.           .then(function (urlToPaste) {
  314.             const embed = new MessageEmbed()
  315.               .setAuthor({
  316.                 name: 'LOG',
  317.                 iconURL: `https://cdn.discordapp.com/icons/778969600591134740/b581f0c2573cfdab3ceab45ba0545c78.webp`,
  318.               })
  319.               .setDescription(`📰 Dzienniki biletów \`${chan.id}\` stworzone przez <@!${chan.topic}> i Usuniety przez <@!${interaction.user.id}>\n\nLogs: [**Kliknij tutaj, aby zobaczyć dzienniki**](${urlToPaste})`)
  320.               .setColor('YELLOW')
  321.               .setTimestamp();
  322.  
  323.             const embed2 = new MessageEmbed()
  324.             .setAuthor({
  325.               name: 'LOG',
  326.               iconURL: `https://cdn.discordapp.com/icons/778969600591134740/b581f0c2573cfdab3ceab45ba0545c78.webp`,
  327.             })
  328.               .setDescription(`📰 Dzienniki biletu \`${chan.id}\`: [**Kliknij tutaj, aby zobaczyć dzienniki**](${urlToPaste})`)
  329.               .setColor('2f3136')
  330.               .setTimestamp();
  331.  
  332.             client.channels.cache.get("933767785320964127").send({
  333.               embeds: [embed]
  334.             });
  335.             client.users.cache.get(chan.topic).send({
  336.               embeds: [embed2]
  337.             }).catch(() => {console.log('Nie mogę go dm :(')});
  338.             chan.send('Usuwanie kanałów...');
  339.  
  340.             setTimeout(() => {
  341.               chan.delete();
  342.             }, 5000);
  343.           });
  344.       });
  345.     };
  346.   }
  347. })
  348.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement