DiscordTickets/commands/close.js

52 lines
1.7 KiB
JavaScript
Raw Normal View History

2019-05-04 18:09:05 +03:00
const Discord = require('discord.js');
const config = require('../config.json');
2019-05-06 19:18:43 +03:00
const log = require(`leekslazylogger`);
2020-08-03 18:39:39 +03:00
2019-05-04 18:09:05 +03:00
module.exports = {
name: 'close',
description: 'Close a ticket',
usage: '',
aliases: ['none'],
example: '',
args: false,
cooldown: config.cooldown,
guildOnly: true,
execute(message, args) {
const client = message.client;
// command starts here
message.delete();
if(!message.channel.name.startsWith('ticket-')) { // // !message.channel.name.length() == 15 &&
2019-05-05 20:42:56 +03:00
if(config.useEmbeds) {
const notTicket = new Discord.RichEmbed()
.setColor("#E74C3C")
2020-08-03 18:39:39 +03:00
.setDescription(`:x: **This command can only be used within a ticket channel**`);
2019-05-05 20:42:56 +03:00
return message.channel.send(notTicket);
} else {
2020-08-03 18:39:39 +03:00
return message.channel.send(`:x: **This command can only be used within a ticket channel**`);
2019-05-05 20:42:56 +03:00
}
} else {
try {
2020-08-03 18:39:39 +03:00
message.channel.delete();
2019-05-05 20:42:56 +03:00
// log
2020-08-03 18:39:39 +03:00
if (config.useEmbeds) {
2019-05-05 20:42:56 +03:00
const embed = new Discord.RichEmbed()
.setAuthor(`${client.user.username} / Ticket Log`, client.user.avatarURL)
.setTitle("Ticket Closed")
.setColor(config.colour)
.addField("Username", message.author, true)
.addField("Channel", message.channel.name, true)
.setFooter(`DiscordTickets`)
.setTimestamp();
2020-08-03 18:39:39 +03:00
client.channels.get(config.logChannel).send(embed);
2019-05-05 20:42:56 +03:00
} else {
client.channels.get(config.logChannel).send(`Ticket closed by **${message.author.tag} (${message.author.id})**`);
}
2020-08-03 18:39:39 +03:00
log.info(`${message.author.tag} closed a ticket (#${message.channel.name})`);
} catch (error) {
2019-05-06 19:18:43 +03:00
log.error(log.colour.red(error));
2019-05-05 20:42:56 +03:00
}
}
2019-05-04 18:09:05 +03:00
// command ends here
},
};