Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

discord.js ticket system stackoverflow

const discord = require("discord.js");

module.exports.run = async (bot, message, args) => {

    // ID from the catogory channel tickets.
    const categoryId = "644626077704257546";

    // Get username
    var userName = message.author.username;
    // Verkrijg discriminator
    var userDiscriminator = message.author.discriminator;

    // If ticket has been made
    var bool = false;

    // Checking if ticket has been made.
    message.guild.channels.forEach((channel) => {

        // If ticket has been made sent:
        if (channel.name == userName.toLowerCase() + "-" + userDiscriminator) {

            message.channel.send("You already made a ticket");

            bool = true;

        }

    });

    // Ticket return code
    if (bool == true) return;

    var embedCreateTicket = new discord.RichEmbed()
        .setTitle("Hey, " + message.author.username)
        .setFooter("Support channel will be made");

    message.channel.send(embedCreateTicket);

    // Create channel and put it in the right catogary
    message.guild.createChannel(userName + "-" + userDiscriminator, "text").then((createdChan) => { // Maak kanaal

        createdChan.setParent(categoryId).then((settedParent) => { // Zet kanaal in category.

            // Put permissions for everyone
            settedParent.overwritePermissions(message.guild.roles.find('name', "@everyone"), { "READ_MESSAGES": false });
            settedParent.overwritePermissions(message.guild.roles.find('name', "@management"), { "VIEW_CHANNEL": true });
            // Put permission by the user that created the ticket
            settedParent.overwritePermissions(message.author, {

                "READ_MESSAGES": true, "SEND_MESSAGES": true,
                "ATTACH_FILES": true, "CONNECT": true,
                "CREATE_INSTANT_INVITE": false, "ADD_REACTIONS": true

            });

            var embedParent = new discord.RichEmbed()
                .setTitle("Hey, " + message.author.username.toString())
                .setDescription("Put down here your question");

            settedParent.send(embedParent);
        }).catch(err => {
            message.channel.send("Something went wrong.");
        });

    }).catch(err => {
        message.channel.send("Something went wrong.");
    });

}

module.exports.help = {
    name: "ticket",
    description: "Create a ticket"
}
Comment

PREVIOUS NEXT
Code Example
Javascript :: sequelize find one 
Javascript :: unable to resolve path to module eslint(import/no-unresolved) absoute path 
Javascript :: how to get only month and year in js 
Javascript :: npm ERR! command /d /s /c node-pre-gyp install --fallback-to-build 
Javascript :: js get difference in days 
Javascript :: style after javascript 
Javascript :: get json data when we get error code in axios 
Javascript :: use js variable in blade route 
Javascript :: setlocalstorage 
Javascript :: jquery text replace 
Javascript :: get docs with date intervals mongoose 
Javascript :: java script cosinus grad 
Javascript :: fetch api post req 
Javascript :: separatly fetch a strings with commas inn js 
Javascript :: pdf dark 
Javascript :: javascript filter strings for partial matches 
Javascript :: check length of number javascript 
Javascript :: tab navigation react-native without title 
Javascript :: req.body empty mongodb 
Javascript :: python http request post json example 
Javascript :: regex for yyyy-mm-dd 
Javascript :: javascript get current week number 
Javascript :: first x characters of string javascript 
Javascript :: mongoose connect url 
Javascript :: javascript check if not null 
Javascript :: media query in react js 
Javascript :: js array intersection object 
Javascript :: floating point in javascript 
Javascript :: showing an image in react js 
Javascript :: how to creat a function 
ADD CONTENT
Topic
Content
Source link
Name
7+7 =