Untitled

 avatar
unknown
plain_text
2 years ago
4.2 kB
3
Indexable
const { MessageEmbed, MessageAttachment } = require('discord.js');

// Ticket Generale
module.exports = {
    name: "interactionCreate",
    async execute(interaction) {
        if (interaction.customId == 'close') {
            let topic = interaction.channel.topic;
           
            if (topic.startsWith("PUser ID:") || topic.startsWith("GUser ID:") || topic.startsWith("HUser ID:")) {
                let idUtente = topic.slice(10);
        
                if (interaction.member.roles.cache.has("1065297167574646804") || interaction.member.roles.cache.has("979423088787730452")) {
                   
                    const embed1 = new MessageEmbed()
                    .setColor('RANDOM')
                    .setDescription(`> <@${interaction.user.id}> Il ticket verrà chiuso tra pochi secondi!`)
                    .setFooter({ text: 'MAZE - Call Of Duty', iconURL: 'https://cdn.discordapp.com/attachments/1061877160941461565/1062442140296286238/icona.png' });

                    interaction.reply({ embeds:[embed1] })

                    const getAllMessages = async (channel) => {
                        let allMessages = []
                        let lastMessage
                    
                        while (true) {
                            const options = { limit: 100 }
                            if (lastMessage) options.before = lastMessage
                    
                            let messages = await channel.messages.fetch(options)
                    
                            allMessages = allMessages.concat(Array.from(messages.values()))
                    
                            lastMessage = messages.last().id
                    
                            if (messages.size != 100) {
                                break
                            }
                        }
                    
                        return allMessages
                    }

                    let chatLog = `-- CHAT LOG #${interaction.channel.name} --\n\n`

                    let messages = await getAllMessages(interaction.channel)
                    messages.reverse().forEach(msg => {
                        chatLog += `@${msg.author.tag} ID: ${msg.author.id} - ${msg.createdAt.toLocaleString('en-GB', { timeZone: 'Europe/Rome' })}\n`
            
                        if (msg.content) chatLog += `${msg.content}\n`
            
                        if (msg.embeds[0]) {
                            chatLog += `Embed:\n`
                            if (msg.embeds[0].title) chatLog += `Title: ${msg.embeds[0].title}\n`
                            if (msg.embeds[0].description) chatLog += `Description: ${msg.embeds[0].description}\n`
                            if (msg.embeds[0].fields[0]) chatLog += `Fields: ${msg.embeds[0].fields.map(x => `${x.name}-${x.value}`).join(", ")}\n`
                        }
            
                        if (msg.attachments.size > 0)
                            chatLog += `Files: ${msg.attachments.map(x => `${x.name} (${x.url})`).join(", ")}\n`
            
                        if (msg.stickers.size > 0)
                            chatLog += `Stickers: ${msg.stickers.map(x => `${x.name} (${x.url})`).join(", ")}\n`
            
                        chatLog += "\n"
                    })
            
                    let attachment = new MessageAttachment(Buffer.from(chatLog, "utf-8"), `chatLog-channel-${interaction.channel.id}.txt`)

                    client.channels.cache.get("979425435043639346").send({content: `Chiuso da: <@${interaction.user.id}>`, files: [attachment] })

                    setTimeout(function () {
                        interaction.channel.delete();
                    }, 5000);
                } else {
                    interaction.reply({ content: `<@${interaction.user.id}>\nNon hai il permesso per chiudere il ticket.`, ephemeral: true })
                }
            } else {
                interaction.reply({ content: "Non hai il permesso per questo il ticket.", ephemeral: true })
            }

        }

    }
}
Editor is loading...