forked from LunarTaku/djs-ticket-system
-
Notifications
You must be signed in to change notification settings - Fork 3
/
ticketModal.js
99 lines (91 loc) · 3.09 KB
/
ticketModal.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
87
88
89
90
91
92
93
94
95
96
97
98
99
const { EmbedBuilder, CommandInteraction } = require("discord.js");
const ticketData = require("../../../Structures/Schemas/ticketData");
const ticketCount = require("../../../Structures/Schemas/ticketCount");
const userData = require("../../../Structures/Schemas/guildTickets");
const { createTranscript } = require("discord-html-transcripts");
module.exports = {
id: "ticketModal",
/**
*
* @param {CommandInteraction} interaction
*/
async execute(interaction) {
const { guild, member, channel } = interaction;
const ticketDB = await ticketData.findOne({
GuildId: interaction.guild.id,
});
if (!ticketDB)
return interaction.reply({
embeds: [
new EmbedBuilder()
.setColor("#303135")
.setDescription(`Can't find any data on the ticket system:/`),
],
ephemeral: true,
});
const userDB = await userData.findOne({ GuildId: interaction.guild.id });
if (!userDB)
return interaction.reply({
embeds: [
new EmbedBuilder()
.setColor("#303135")
.setDescription(`Can't find any data on this ticket:/`),
],
ephemeral: true,
});
const attachment = await createTranscript(channel, {
limit: -1,
returnType: "attachment",
saveImages: true,
minify: true,
fileName: `Ticket-${guild.name}.html`,
});
await userData.updateOne({ ChannelID: channel.id }, { Closed: true });
const TicketCount = ticketCount.findOne({ GuildID: guild.id });
const Count = ((await TicketCount.countDocuments())).toString();
const Channel = guild.channels.cache.get(ticketDB.Transcript);
const Target = guild.members.cache.get(userDB.OwnerID);
const input = interaction.fields.getTextInputValue("Close_Reason_Ticket");
const Embed = new EmbedBuilder().setColor(`#303135`).setFields({
name: `Ticket Information`,
value: `
**ID:** ${Count}
**Close Reason:** ${input}
**Closed By:** ${member}
**Claimed By:** ${userDB.ClaimedBy ? `<@${userDB.ClaimedBy}>` : "None"}
**Ticket Owner:** <@${userDB.OwnerID}>
`,
});
Channel.send({
embeds: [Embed],
files: [attachment],
});
Target.send({
embeds: [Embed],
files: [attachment],
}).catch((err) =>
guild.channels.cache.get(ticketDB.ErrorLog).send({
embeds: [
new EmbedBuilder()
.setTitle(`Couldn't DM user`)
.setColor("#303135")
.addFields({
name: `Error Information`,
value: `**Mention Tag:** <@${userData.OwnerID}>\n**ID:** ${userData.OwnerID}`,
}),
],
})
);
await interaction.deferReply({
embeds: [
new EmbedBuilder()
.setColor("#303135")
.setDescription(`Closing Ticket...`),
],
});
userData
.findOneAndDelete({ GuildID: guild.id, ChannelID: channel.id })
.catch((err) => console.log(err));
channel.delete();
},
};