Skip to content

Commit

Permalink
add clear command
Browse files Browse the repository at this point in the history
  • Loading branch information
zuedev committed Dec 10, 2024
1 parent a08a358 commit bf49193
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions source/InteractionCreate.Commands/tracker.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { PermissionFlagsBits } from "discord.js";
import { SlashCommandBuilder } from "@discordjs/builders";
import { connect } from "../controllers/mongo.js";

Expand Down Expand Up @@ -43,6 +44,11 @@ export default {
subcommand
.setName("list")
.setDescription("List all the things in the tracker")
)
.addSubcommand((subcommand) =>
subcommand
.setName("clear")
.setDescription("Clear all the things from the tracker")
),
async execute({ interaction }) {
const subcommand = interaction.options.getSubcommand();
Expand All @@ -57,6 +63,9 @@ export default {
case "list":
await list({ interaction });
break;
case "clear":
await clear({ interaction });
break;
default:
await interaction.reply("This subcommand is not supported.");
break;
Expand Down Expand Up @@ -192,3 +201,26 @@ async function list({ interaction }) {

await interaction.reply(message);
}

async function clear({ interaction }) {
// check if the user has the MANAGE_CHANNELS permission
if (
!interaction.channel
.permissionsFor(interaction.member)
.has(PermissionFlagsBits.ManageChannels)
)
return await interaction.reply(
"You must have the `MANAGE_CHANNELS` permission to clear the tracker."
);

const mongo = await connect();

await mongo
.db(process.env.ENVIRONMENT)
.collection("trackers")
.deleteMany({ channel: interaction.channel.id });

await mongo.close();

await interaction.reply("All items have been cleared from the tracker.");
}

0 comments on commit bf49193

Please sign in to comment.