Skip to content

Commit

Permalink
Add optional reason to the ticket delete slash command
Browse files Browse the repository at this point in the history
  • Loading branch information
ralphkb committed Sep 3, 2024
1 parent d5fcdbd commit 5a1a7a2
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 4 deletions.
10 changes: 9 additions & 1 deletion commands/Tickets/delete.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@ module.exports = {
data: new SlashCommandBuilder()
.setName("delete")
.setDescription("Delete a ticket.")
.addStringOption((option) =>
option
.setName("reason")
.setDescription("The reason for deleting the ticket")
.setRequired(false),
)
.setDefaultMemberPermissions(
PermissionFlagsBits[config.commands.delete.permission],
)
Expand All @@ -35,6 +41,8 @@ module.exports = {
}

await interaction.deferReply();
await deleteTicket(interaction);
const reason =
interaction.options.getString("reason") || "No reason provided.";
await deleteTicket(interaction, reason);
},
};
3 changes: 2 additions & 1 deletion config.yml.example
Original file line number Diff line number Diff line change
Expand Up @@ -1434,7 +1434,7 @@ logReopenEmbed:
deleteEmbed:
color: "#FF0000"
title: ""
description: "Deleting ticket in {time} seconds" # Use {time} for the time in seconds
description: "Deleting ticket in {time} seconds" # Use {time} for the time in seconds and {reason} for the reason
timestamp: false
URL: ""
image: ""
Expand Down Expand Up @@ -1484,6 +1484,7 @@ logDeleteEmbed:
field_user: "• Ticket Creator"
field_ticket: "• Ticket"
field_creation: "• Creation Time"
field_reason: "• Reason"

# Log embed for automatically deleted tickets
logAutoDeleteEmbed:
Expand Down
10 changes: 8 additions & 2 deletions utils/ticketDelete.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ const {
lastUserMsgTimestamp,
} = require("./mainUtils.js");

async function deleteTicket(interaction) {
async function deleteTicket(interaction, reason = "No reason provided.") {
const channelID = interaction.channel.id;
const channelName = interaction.channel.name;
const totalMessages = await mainDB.get("totalMessages");
Expand Down Expand Up @@ -66,6 +66,10 @@ async function deleteTicket(interaction) {
name: config.logDeleteEmbed.field_creation || "• Creation Time",
value: `> <t:${await ticketsDB.get(`${channelID}.creationTime`)}:F>`,
},
{
name: config.logDeleteEmbed.field_reason || "• Reason",
value: `> ${reason}`,
},
]);

if (claimUser)
Expand Down Expand Up @@ -97,7 +101,9 @@ async function deleteTicket(interaction) {

if (deleteEmbed.data && deleteEmbed.data.description) {
deleteEmbed.setDescription(
deleteEmbed.data.description.replace(/\{time\}/g, `${deleteTicketTime}`),
deleteEmbed.data.description
.replace(/\{time\}/g, `${deleteTicketTime}`)
.replace(/\{reason\}/g, reason),
);
}

Expand Down

0 comments on commit 5a1a7a2

Please sign in to comment.