-
Notifications
You must be signed in to change notification settings - Fork 2
/
ticketSetup.js
106 lines (102 loc) · 3.68 KB
/
ticketSetup.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
100
101
102
103
104
105
106
/*
Copyright 2021 Aman Verma. All rights reserved.
Use of this source code is governed by a MIT license that can be
found in the LICENSE file.
*/
const { MessageEmbed } = require("discord.js");
module.exports = {
name: "ticketsetup",
description: "Sets up the Ticketing System",
run: async (client, message) => {
if (!message.member.permissions.has("ADMINISTRATOR"))
return message.reply(`Become a admin MAN`);
let sent, category, logChannel, channel;
//creating tickets category
try {
category = await message.guild.channels.create("Tickets", {
type: "GUILD_CATEGORY"
});
} catch (er) {
return message.reply(
"Failed to create a category while setting up" + `Error ${er}`
);
}
const role = message.guild.roles.cache.find(
(role) => role.name === "Support Team"
);
//if role is not found, create it
if (!role)
try {
role = await message.guild.roles.create({
name: "Support Team",
color: "BLUE",
reason: "Support team for ticketing system"
});
} catch (e) {
return message.reply(
`Failed to create the Support role . Error : ${e}`
);
}
//creating ticket channel
try {
channel = await message.guild.channels.create("🎫-tickets", {
type: "text",
permissionOverwrites: [
{
id: message.guild.roles.everyone,
deny: [
"VIEW_CHANNEL",
"SEND_MESSAGES",
"READ_MESSAGE_HISTORY"
] //Deny permissions
}
],
parent: category.id
});
} catch (e) {
return message.reply("Failed to Create Ticket channel. Error" + e);
}
//sending message to the channel
try {
const embed = new MessageEmbed()
.setTitle("Ticket System")
.setDescription("React to open a ticket!")
.setFooter("Ticket System")
.setColor("00ff00");
sent = await channel.send({
embeds: [embed]
});
} catch (e) {
return message.reply(`Failed to Send the message. Error : ${e}`);
}
//creating log channel
try {
logChannel = await message.guild.channels.create("tickets-log", {
type: "text",
permissionOverwrites: [
{
id: message.guild.roles.everyone,
deny: [
"VIEW_CHANNEL",
"SEND_MESSAGES",
"READ_MESSAGE_HISTORY"
] //Deny permissions
}
],
parent: category.id
});
} catch (e) {
return message.reply("Failed to Create log channel. Error" + e);
}
sent.react("🎫");
message.channel.send(
"Ticket System Setup Done! Here are the values" +
`\n\nticketCategoryId : ${category.id}` +
`\nlogChannelId: ${logChannel.id}` +
`\nticketMessageId: ${sent.id}` +
"\n\nRunning this command again will create another set of configuration" +
`\n Also <@&${role.id}> will be having access to the tickets`
);
},
aliases: []
};