0

I am trying to make a ticket system, but there is a problem. I want to make it when somebody opens a ticket, wait until the ticket closes, and then let them react again. (cooldown)

Here is my code:

client.on('messageReactionAdd', async (reaction, user) => {
    if (user.partial) await user.fetch();
    if (reaction.partial) await reaction.fetch();
    if (reaction.message.partial) await reaction.message.fetch();
    if (user.bot) return; {
        let ticketid = await db.get(`tickets_${reaction.message.guild.id}`);
        if (!ticketid) return;
        if (reaction.message.id == ticketid && reaction.emoji.name == ':tickets:') {
            db.add(`ticketnumber_${reaction.message.guild.id}`, 1)
            let ticketnumber = await db.get(`ticketnumber_${reaction.message.guild.id}`)
            if (ticketnumber === null) ticketnumber = "1"
            reaction.users.remove(user);
            let CH = message.guild.channels.find(r => r.id == '770687676152020993');
            if (!CH) return;
            reaction.message.guild.channels.create(`ticket-${ticketnumber}`, {
                type: 'text', parent: CH, reason: 'Reaction Tickets System',
                permissionOverwrites: [
                    {
                        id: user.id,
                        allow: ["SEND_MESSAGES", "VIEW_CHANNEL"]
                    },
                    {
                        id: reaction.message.guild.roles.everyone,
                        deny: ["VIEW_CHANNEL"]
                    }
                ],
                type: 'text'
            }).then(async channel => {
                let data = {
                    channelid: channel.id
                }
                db.push(`tickets`, data).then(console.log)
                channel.send(`<@${user.id}>`).then(log => { db.set(`mention_${channel.id}`, log.id) })
                db.set(`ticketauthor_${channel.id}`, user.id)
                let icon = reaction.message.guild.iconURL()
                let ticketmsg = await channel.send(new Discord.MessageEmbed()
                    .setTitle(`${user.username} Ticket`)
                    .setDescription("We are going to contact you as soon\n Click the reaction to close the ticket:closed_lock_with_key:")
                    .setFooter(reaction.message.guild.name, icon)
                    .setTimestamp()
                );
                ticketmsg.react(':closed_lock_with_key:')
                console.log(`${ticketmsg.id}`)
                db.set(`closeticket_${channel.id}`, ticketmsg.id)
            })
        }
    }
});
DataMind
  • 69
  • 1
  • 9
Abod
  • 23
  • 3
  • 2
    Please use indentation to make your code more readable to others. – SuperStormer Apr 24 '21 at 19:15
  • Hello @Adob, please indent your code, also I recommend you to write the specific error and the specific piece of code that you are intending to execute, and the specific error, due to we don't have enough context is really hard to help you in that case. – Juan Caicedo Apr 24 '21 at 19:21

1 Answers1

0

I'm not sure if there is a way to catch the id of the user who reacted "I'll put "${reaction.author.id}" as an example because I don't know how but if you know how then you can do it by changing the created channel name to:

const ch = message.guild.channels.cache.find(ch => ch.name.toLowerCase() === `ticket-${reaction.author.id}`)

if(ch) return

reaction.message.guild.channels.create(`ticket-${reaction.author.id}`, {
                type: 'text', parent: CH, reason: 'Reaction Tickets System',
                permissionOverwrites: [
                    {
                        id: user.id,
                        allow: ["SEND_MESSAGES", "VIEW_CHANNEL"]
                    },
                    {
                        id: reaction.message.guild.roles.everyone,
                        deny: ["VIEW_CHANNEL"]
                    }
                ],
                type: 'text'
            })

I'm not sure if there is a way to catch the id of the user who reacted "I'll put "${reaction.author.id}" as an example because I don't know how but if you know how then you can do it by changing the created channel name to:

const example = message.guild.channels.cache.find(ch => ch.name.toLowerCase() === `ticket-${reaction.author.id}`)

if(example) return

reaction.message.guild.channels.create(`ticket-${reaction.author.id}`, {
                type: 'text', parent: CH, reason: 'Reaction Tickets System',
                permissionOverwrites: [
                    {
                        id: user.id,
                        allow: ["SEND_MESSAGES", "VIEW_CHANNEL"]
                    },
                    {
                        id: reaction.message.guild.roles.everyone,
                        deny: ["VIEW_CHANNEL"]
                    }
                ],
                type: 'text'
            })