MCPcopy Index your code
hub / github.com/codebymitch/TitanBot / handleDelete

Function handleDelete

src/commands/ServerStats/modules/serverstats_delete.js:8–63  ·  view source on GitHub ↗
(interaction, client)

Source from the content-addressed store, hash-verified

6
7import { InteractionHelper } from '../../../utils/interactionHelper.js';
8export async function handleDelete(interaction, client) {
9 const guild = interaction.guild;
10 const counterId = interaction.options.getString("counter-id");
11
12 try {
13 await InteractionHelper.safeDefer(interaction);
14 } catch (error) {
15 logger.error("Failed to defer reply:", error);
16 return;
17 }
18
19 if (!interaction.member.permissions.has(PermissionFlagsBits.ManageChannels)) {
20 await replyUserError(interaction, { type: ErrorTypes.PERMISSION, message: 'You need **Manage Channels** permission to delete counters.' }).catch(logger.error);
21 return;
22 }
23
24 try {
25 const counters = await getServerCounters(client, guild.id);
26
27 if (counters.length === 0) {
28 await replyUserError(interaction, { type: ErrorTypes.USER_INPUT, message: 'No counters found to delete.' }).catch(logger.error);
29 return;
30 }
31
32 const counterToDelete = counters.find(c => c.id === counterId);
33 if (!counterToDelete) {
34 await replyUserError(interaction, { type: ErrorTypes.USER_INPUT, message: 'Counter with ID \\`${counterId}\\` not found. Use \\`/counter list\\` to see all counters.' }).catch(logger.error);
35 return;
36 }
37
38 const channel = guild.channels.cache.get(counterToDelete.channelId);
39
40 const embed = createEmbed({
41 title: "Delete Counter & Channel",
42 description: `Are you sure you want to delete this counter and its channel?\n\n**ID:** \`${counterToDelete.id}\`\n**Type:** ${getCounterTypeDisplay(counterToDelete.type)}\n**Channel:** ${channel || 'Deleted Channel'}\n\n **The channel will be permanently deleted!**`,
43 color: getColor('error')
44 });
45
46 const row = new ActionRowBuilder().addComponents(
47 new ButtonBuilder()
48 .setCustomId(`counter-delete:confirm:${counterToDelete.id}:${interaction.user.id}`)
49 .setLabel("Confirm Delete")
50 .setStyle(ButtonStyle.Danger),
51 new ButtonBuilder()
52 .setCustomId(`counter-delete:cancel:${counterToDelete.id}:${interaction.user.id}`)
53 .setLabel("Cancel")
54 .setStyle(ButtonStyle.Secondary)
55 );
56
57 await InteractionHelper.safeEditReply(interaction, { embeds: [embed], components: [row] }).catch(logger.error);
58
59 } catch (error) {
60 logger.error("Error in handleDelete:", error);
61 await replyUserError(interaction, { type: ErrorTypes.UNKNOWN, message: 'An error occurred while fetching counters. Please try again.' }).catch(logger.error);
62 }
63}
64
65export async function performDeletionByCounterId(client, guild, counterId) {

Callers 1

executeFunction · 0.90

Calls 8

getServerCountersFunction · 0.90
createEmbedFunction · 0.90
getColorFunction · 0.90
replyUserErrorFunction · 0.85
safeDeferMethod · 0.80
safeEditReplyMethod · 0.80
getCounterTypeDisplayFunction · 0.70
getMethod · 0.45

Tested by

no test coverage detected