discord js ticket system

Solutions on MaxInterview for discord js ticket system by the best coders in the world

showing results for - "discord js ticket system"
Samuel
26 Jan 2020
1const discord = require("discord.js");
2
3module.exports.run = async (bot, message, args) => {
4
5    // ID from the catogory channel tickets.
6    const categoryId = "644626077704257546";
7
8    // Get username
9    var userName = message.author.username;
10    // Verkrijg discriminator
11    var userDiscriminator = message.author.discriminator;
12
13    // If ticket has been made
14    var bool = false;
15
16    // Checking if ticket has been made.
17    message.guild.channels.forEach((channel) => {
18
19        // If ticket has been made sent:
20        if (channel.name == userName.toLowerCase() + "-" + userDiscriminator) {
21
22            message.channel.send("You already made a ticket");
23
24            bool = true;
25
26        }
27
28    });
29
30    // Ticket return code
31    if (bool == true) return;
32
33    var embedCreateTicket = new discord.RichEmbed()
34        .setTitle("Hey, " + message.author.username)
35        .setFooter("Support channel will be made");
36
37    message.channel.send(embedCreateTicket);
38
39    // Create channel and put it in the right catogary
40    message.guild.createChannel(userName + "-" + userDiscriminator, "text").then((createdChan) => { // Maak kanaal
41
42        createdChan.setParent(categoryId).then((settedParent) => { // Zet kanaal in category.
43
44            // Put permissions for everyone
45            settedParent.overwritePermissions(message.guild.roles.find('name', "@everyone"), { "READ_MESSAGES": false });
46            settedParent.overwritePermissions(message.guild.roles.find('name', "@management"), { "VIEW_CHANNEL": true });
47            // Put permission by the user that created the ticket
48            settedParent.overwritePermissions(message.author, {
49
50                "READ_MESSAGES": true, "SEND_MESSAGES": true,
51                "ATTACH_FILES": true, "CONNECT": true,
52                "CREATE_INSTANT_INVITE": false, "ADD_REACTIONS": true
53
54            });
55
56            var embedParent = new discord.RichEmbed()
57                .setTitle("Hey, " + message.author.username.toString())
58                .setDescription("Put down here your question");
59
60            settedParent.send(embedParent);
61        }).catch(err => {
62            message.channel.send("Something went wrong.");
63        });
64
65    }).catch(err => {
66        message.channel.send("Something went wrong.");
67    });
68
69}
70
71module.exports.help = {
72    name: "ticket",
73    description: "Create a ticket"