Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const Discord = require ("discord.js");
- const fs = require("fs");
- const ms = require('ms');
- module.exports.run = async (bot, message, args) => {
- const products = JSON.parse(fs.readFileSync("./data/products.json", "utf8"));
- const configcolours = require("../config/colours.json");
- const configperms = require("../config/permissions.json");
- const configmessages = require("../config/messages.json");
- const configchannels = require("../config/channels.json");
- var ticketChannel = {};
- const ticketrole = message.guild.roles.find(x => x.name === configperms.ticketaccess)
- //console.log(message.guild.roles.map(r => r.name))
- let description = args.slice(0).join(' ')
- if(!description) {
- message.delete();
- let usage = new Discord.RichEmbed()
- .setColor(configcolours.general)
- .setDescription(configmessages.ticketusage)
- .setTimestamp()
- message.channel.send(usage).then(msg => msg.delete(5000));
- }
- else if(!ticketrole) {
- console.log('\x1b[31m\x1b[1m', '\n[ERROR] Could not find role named ' + configperms.ticketaccess + ". (-new)\n" + '\x1b[0m')
- message.channel.send("**[ERROR]** Could not find role named " + configperms.ticketaccess + ".")
- return;
- }
- else if(!configchannels.ticketscategory) {
- console.log('\x1b[31m\x1b[1m', '\n[ERROR] Could not find category with the id ' + configchannels.ticketscategory + ". (-new)\n" + '\x1b[0m')
- message.channel.send("**[ERROR]** Could not find category with the id " + configchannels.ticketscategory + ".")
- return;
- }
- else {
- message.delete();
- let ticketmessage = new Discord.RichEmbed()
- .setColor(configcolours.general)
- .setTitle(message.author.username + " - " + message.author.id)
- .setDescription(' ')
- .addField("Description", description)
- .setThumbnail(message.author.avatarURL)
- .setTimestamp()
- async function Question(QChannel, callBack){
- const filter = m => m.content.includes('');
- const collector = QChannel.createMessageCollector(filter, { time: 15000 });
- collector.on('collect', m => {
- collector.stop()
- return callBack(m)
- });
- }
- message.guild.createChannel(`ticket-${message.author.username}`, {type:"text"}).then(async c => {
- c.setParent(configchannels.ticketscategory);
- c.overwritePermissions(message.guild.defaultRole, {
- VIEW_CHANNEL: false
- })
- c.overwritePermissions(message.member, {
- VIEW_CHANNEL: true
- })
- c.overwritePermissions(ticketrole, {
- VIEW_CHANNEL: true,
- SEND_MESSAGES: true
- })
- let log = `-\n` +
- `Client ID: ${message.author.id}\n` +
- `-\n`;
- fs.writeFile(`tickets/${c.id}.txt`, log, (err) => {
- if (err) throw err;
- });
- const ticketcreated = new Discord.RichEmbed()
- .setDescription(`Your ticket has been created! Visit your ticket at ${c}`)
- message.channel.send(ticketcreated).then(msg => msg.delete(5000));
- ticketChannel = c
- let tickets = JSON.parse(fs.readFileSync("./data/tickets.json", "utf8"));
- tickets[c.id] = {
- "owner": message.author.id
- };
- fs.writeFile("./data/tickets.json", JSON.stringify(tickets, null, 2), (err) => {
- if (err) console.log(err)
- });
- }).then(m => {
- const product = new Discord.RichEmbed()
- .setDescription("Hello " + message.author.username + ",\nWhat product would you like to order?")
- ticketChannel.send(product).then(m => {
- for(var i = 0; i < 2; i++) {
- Question(ticketChannel, function(response) {
- console.log(response.content)
- if(response.content != "dave") {
- const productIssue = new Discord.RichEmbed()
- .setDescription("Invalid Product, Please try again!")
- ticketChannel.send(productIssue);
- i = 0
- }
- else {
- i = 0
- }
- })
- }
- })
- })
- }
- }
- module.exports.config = {
- name: "new",
- aliases: ["ticket"]
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement