-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathticket.js
86 lines (72 loc) · 3.38 KB
/
ticket.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
const { MessageEmbed, MessageActionRow, MessageButton } = require('discord.js');
const { categoryId, guildId, supportRole, logsChannel } = require('./config.json');
module.exports.closeTicket = async (interaction, tickets, db, client) => {
let channelId = interaction.customId.split("-")[1];
let guild = client.guilds.cache.get(guildId);
let channel = guild.channels.cache.get(channelId);
await channel.delete(`Ticket closed by ${interaction.user.username} (ID: ${interaction.user.id})`);
const logs = client.channels.cache.get(logsChannel);
const logEmbed = new MessageEmbed()
.setTitle("Ticket closed")
.setColor(tickets.color)
.setTimestamp()
.setDescription(`Name: ${tickets.title}\nUser: <@${interaction.user.id}>\nTicket category ID: ${tickets.id}`);
await logs.send({ embeds: [logEmbed], content: "Ticket closed succesfully." });
}
module.exports.createTicket = async (interaction, tickets, client) => {
if ((new Date() - new Date(client.cooldowns.get(interaction.user.id)) < 15 * 60 * 1000))
return interaction.reply({ content: "You have already created a ticket in the last 15 minutes, please wait a while!", ephemeral: true });
else
client.cooldowns.set(interaction.user.id, new Date());
let guild = client.guilds.cache.get(guildId);
let category = guild.channels.cache.get(categoryId);
let channel = await guild.channels.create(
"ticket-" + interaction.user.username,
{
parent: category,
topic: tickets.title,
reason: `Ticket requested by <@${interaction.user.id}>.`,
permissionOverwrites: [
{
id: guild.roles.everyone,
deny: ['VIEW_CHANNEL', 'SEND_MESSAGES']
},
{
id: client.user,
allow: ['VIEW_CHANNEL', 'SEND_MESSAGES', 'ATTACH_FILES', 'READ_MESSAGE_HISTORY']
},
{
id: interaction.user,
allow: ['VIEW_CHANNEL', 'SEND_MESSAGES', 'ATTACH_FILES', 'READ_MESSAGE_HISTORY']
},
{
id: supportRole,
allow: ['VIEW_CHANNEL', 'SEND_MESSAGES', 'ATTACH_FILES', 'READ_MESSAGE_HISTORY']
}
]
}
);
const embed = new MessageEmbed()
.setDescription(`Hi there <@${interaction.user.id}>!\nPlease wait for support staff to assist you`)
.setColor(tickets.color);
const row = new MessageActionRow()
.addComponents(
new MessageButton()
.setCustomId("close-" + channel.id + "-" + tickets.id)
.setLabel("🔒 Close ticket")
.setStyle('PRIMARY'),
);
await channel.send({
content: `<@${interaction.user.id}> <@&${supportRole}>`,
embeds: [embed],
components: [row]
})
await interaction.reply({ content: `Ticket created in <#${channel.id}>!`, ephemeral: true });
const logs = client.channels.cache.get(logsChannel);
const logEmbed = new MessageEmbed()
.setTitle("Ticket created")
.setColor(tickets.color)
.setTimestamp()
.setDescription(`Name: ${tickets.title}\nUser: <@${interaction.user.id}>\nTicket category ID: ${tickets.id}`);
await logs.send({ embeds: [logEmbed], content: "Ticket created succesfully." });
}