forked from amanv8060/DSCKIIT-BOT
-
Notifications
You must be signed in to change notification settings - Fork 0
/
messageReactionAdd.js
67 lines (63 loc) · 2.48 KB
/
messageReactionAdd.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
/*
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 Discord = require("discord.js");
const data = require("../../../data/data.json");
module.exports = async (client, 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 = data["ticketMessageId"];
if (!ticketid) return;
if (reaction.message.id == ticketid && reaction.emoji.name == "🎫") {
if (
reaction.message.guild.channels.cache.some(
(channel) => channel.name.toLowerCase() === "ticket-" + user.id
)
) {
reaction.users.remove(user);
user.send("You already have a ticket");
} else {
reaction.users.remove(user);
reaction.message.guild.channels
.create(`ticket-${user.id}`, {
permissionOverwrites: [
{
id: user.id,
allow: ["SEND_MESSAGES", "VIEW_CHANNEL"]
},
{
id: reaction.message.guild.roles.everyone,
deny: ["VIEW_CHANNEL"]
},
{
id: reaction.message.guild.roles.cache.find(
(role) => role.name === "Support Team"
),
allow: ["SEND_MESSAGES", "VIEW_CHANNEL"]
}
],
type: "text",
parent: data["ticketCategoryId"]
})
.then(async (channel) => {
const embed = new Discord.MessageEmbed()
.setTitle("Welcome to your ticket!")
.setDescription(
"Support Team will be with you shortly \n Use `?ticketclose command in this channel to close your ticket`"
)
.setColor("RANDOM");
channel.send({
content: `<@${user.id}>`,
embeds: [embed]
});
})
.catch((err) => {
console.log(err);
});
}
}
};