how to make a ticket system discord.js code example
Example: discord.js ticket system
const discord = require("discord.js");
module.exports.run = async (bot, message, args) => {
const categoryId = "644626077704257546";
var userName = message.author.username;
var userDiscriminator = message.author.discriminator;
var bool = false;
message.guild.channels.forEach((channel) => {
if (channel.name == userName.toLowerCase() + "-" + userDiscriminator) {
message.channel.send("You already made a ticket");
bool = true;
}
});
if (bool == true) return;
var embedCreateTicket = new discord.RichEmbed()
.setTitle("Hey, " + message.author.username)
.setFooter("Support channel will be made");
message.channel.send(embedCreateTicket);
message.guild.createChannel(userName + "-" + userDiscriminator, "text").then((createdChan) => {
createdChan.setParent(categoryId).then((settedParent) => {
settedParent.overwritePermissions(message.guild.roles.find('name', "@everyone"), { "READ_MESSAGES": false });
settedParent.overwritePermissions(message.guild.roles.find('name', "@management"), { "VIEW_CHANNEL": true });
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"