Skip to content

Commit

Permalink
ticket category & delete command
Browse files Browse the repository at this point in the history
feat: ticket category & delete command
  • Loading branch information
FnrDev authored Nov 20, 2021
2 parents 7d21b3c + ff20f7a commit b65a7ad
Show file tree
Hide file tree
Showing 7 changed files with 90 additions and 0 deletions.
24 changes: 24 additions & 0 deletions commands/info/help.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,12 @@ module.exports = {
description: "Show all commands in info category.",
emoji: "ℹ",
value: "info"
},
{
label: "Ticket",
description: "Show all commands in ticket category.",
emoji: "📃",
value: "ticket"
}
])
)
Expand Down Expand Up @@ -99,6 +105,24 @@ module.exports = {
components: []
});
}
if (i.values.includes('ticket')) {
await i.deferUpdate();
let loopTicketCategory = '';
client.commands.filter(r => r.category === 'ticket').forEach(cmd => {
if (!cmd.description) return;
loopTicketCategory += `**\`/${cmd.name}\`** - ${cmd.description}\n`;
});
const embed = new MessageEmbed()
.setTitle('Ticket Commands:')
.setDescription(loopTicketCategory)
.setColor(interaction.guild.me.displayHexColor)
.setFooter(`Requested by ${interaction.user.tag}`, interaction.user.displayAvatarURL({ dynamic: true }))
return i.editReply({
embeds: [embed],
content: null,
components: []
})
}
})
}
}
1 change: 1 addition & 0 deletions commands/ticket/addUser.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ module.exports = {
required: true
}
],
category: "ticket",
timeout: 3000,
modOnly: true,
ticketOnly: true,
Expand Down
61 changes: 61 additions & 0 deletions commands/ticket/delete.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
const { MessageActionRow, MessageButton, MessageEmbed } = require('discord.js');
const settings = require('../../settings.json');

module.exports = {
name: "delete",
description: "Delete a ticket channel.",
modOnly: true,
ticketOnly: true,
category: "ticket",
run: async(interaction, client) => {
const row = new MessageActionRow()
.addComponents(
new MessageButton()
.setCustomId('delete_ticket')
.setStyle('DANGER')
.setLabel('Delete')
)
.addComponents(
new MessageButton()
.setCustomId('cancel')
.setStyle('SECONDARY')
.setLabel('Cancel')
)
await interaction.reply({
content: `Are you sure to delete **#${interaction.channel.name}** ticket.`,
fetchReply: true,
components: [row]
});
const filter = i => i.customId === 'delete_ticket' || 'cancel' && i.user.id === interaction.user.id;
const collector = interaction.channel.createMessageComponentCollector({ filter: filter, time: 20000 });
collector.on('collect', async i => {
if (i.customId === 'delete_ticket') {
const logChannel = client.channels.cache.get(settings.logChannel);
if (!logChannel) return;
const embed = new MessageEmbed()
.setAuthor(interaction.user.tag, interaction.user.displayAvatarURL({ dynamic: true }))
.setDescription(`${interaction.user} deleted a **#${interaction.channel.name}** ticket.`)
.addField("Ticket ID:", interaction.channel.id, true)
.addField("Ticket Created At:", `<t:${Math.floor(interaction.channel.createdTimestamp / 1000)}:R>`, true)
.addField("Ticket Deleted At:", `<t:${Math.floor(Date.now() / 1000)}:R>`, true)
.setColor(settings.embedColor)
.setTimestamp()
.setThumbnail(interaction.user.displayAvatarURL({ dynamic: true }))
await logChannel.send({
embeds: [embed]
})
return interaction.channel.delete(`By: ${interaction.user.tag}`);
}
if (i.customId === 'cancel') {
await interaction.deleteReply();
}
});
collector.on('end', async i => {
try {
await interaction.deleteReply();
} catch (e) {
return false;
}
})
}
}
1 change: 1 addition & 0 deletions commands/ticket/new.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ module.exports = {
name: "new",
description: "Create a new ticket",
timeout: 10000,
category: "ticket",
run: async(interaction, client) => {
const ticketCatgory = interaction.guild.channels.cache.find(r => r.type === 'GUILD_CATEGORY' && r.name === 'tickets');
if (!ticketCatgory) {
Expand Down
1 change: 1 addition & 0 deletions commands/ticket/removeUser.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ module.exports = {
timeout: 3000,
ticketOnly: true,
modOnly: true,
category: "ticket",
run: async(interaction) => {
const member = interaction.options.getMember('user');
if (!interaction.channel.permissionsFor(member).has('VIEW_CHANNEL')) {
Expand Down
1 change: 1 addition & 0 deletions commands/ticket/rename.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ module.exports = {
],
modOnly: true,
ticketOnly: true,
category: "ticket",
run: async(interaction) => {
const name = interaction.options.getString('new_name');
try {
Expand Down
1 change: 1 addition & 0 deletions commands/ticket/setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ module.exports = {
name: "setup",
description: "Setup ticket category in your server",
permission: "ADMINISTRATOR",
category: "ticket",
run: async(interaction, client) => {
const checkTicketCategory = interaction.guild.channels.cache.find(r => r.type === 'GUILD_CATEGORY' && r.name === 'tickets');
if (checkTicketCategory) {
Expand Down

0 comments on commit b65a7ad

Please sign in to comment.