2024-09-26 10:36:29 +01:00
|
|
|
const { SlashCommandBuilder, PermissionFlagsBits } = require("discord.js");
|
2024-09-05 21:29:50 +01:00
|
|
|
const Leaderboard = require("../../models/Leaderboard");
|
|
|
|
|
|
|
|
module.exports = {
|
|
|
|
data: new SlashCommandBuilder()
|
|
|
|
.setName("clearleaderboard")
|
|
|
|
.setDescription("Clears all entries in the trivia leaderboard"),
|
|
|
|
isModOnly: true,
|
|
|
|
|
|
|
|
async execute(interaction) {
|
|
|
|
try {
|
2024-09-25 23:07:02 +01:00
|
|
|
// Check if the user has the Manage Server permission
|
2024-09-26 10:36:29 +01:00
|
|
|
if (
|
|
|
|
!interaction.member.permissions.has(PermissionFlagsBits.ManageGuild)
|
|
|
|
) {
|
2024-09-05 21:29:50 +01:00
|
|
|
await interaction.reply({
|
2024-09-25 23:07:02 +01:00
|
|
|
content: "You do not have permission to use this command!",
|
2024-09-05 21:29:50 +01:00
|
|
|
ephemeral: true,
|
|
|
|
});
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Clear the leaderboard
|
|
|
|
await Leaderboard.deleteMany({});
|
|
|
|
|
|
|
|
// Notify the mod who executed the command
|
|
|
|
await interaction.reply({
|
|
|
|
content: "The leaderboard has been cleared successfully.",
|
|
|
|
ephemeral: true,
|
|
|
|
});
|
|
|
|
} catch (error) {
|
|
|
|
console.error("Error executing clearleaderboard command:", error);
|
|
|
|
await interaction.reply({
|
|
|
|
content: "There was an error while executing this command!",
|
|
|
|
ephemeral: true,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
},
|
|
|
|
};
|