mbot/commands/moderation/clear.js

38 lines
1.6 KiB
JavaScript
Raw Normal View History

const { SlashCommandBuilder, PermissionsBitField } = require('discord.js');
2024-05-11 06:55:44 +00:00
const informationStatus = "[INFO]: ";
const warningStatus = "[WARNING]: ";
const errorStatus = "[ERROR]: ";
const wait = require('node:timers/promises').setTimeout;
2024-05-11 06:55:44 +00:00
module.exports = {
data: new SlashCommandBuilder()
.setName('clear')
.setDescription('Clears a certain amount of text!')
2024-05-16 04:20:51 +00:00
.addIntegerOption(option =>
2024-07-04 09:14:01 +00:00
option.setName('amount')
2024-05-11 06:55:44 +00:00
.setDescription('Set the amount to clear!')
2024-05-16 04:20:51 +00:00
.setMinValue(1)
2024-05-11 06:55:44 +00:00
.setRequired(true)),
async execute(interaction) {
2024-05-16 04:20:51 +00:00
const amount = interaction.options.getInteger('amount');
if(!interaction.member.permissions.has(PermissionsBitField.Flags.ManageMessages)) return interaction.reply({ content: "<:xmark:1238963594758979736> You dont have permission to use this command", ephemeral: true });
2024-05-11 06:55:44 +00:00
try {
await interaction.channel.bulkDelete(amount);
await interaction.reply({ content: `<:checkmark:1238964552482422844> Deleted ${amount} of messages!`, ephemeral: false });
console.log(informationStatus + `Cleared ${amount} amount of text in #${interaction.channel.name} with id of ${interaction.channel.id}`);
await wait(6_000);
2024-05-16 04:20:51 +00:00
await interaction.deleteReply();
2024-05-11 06:55:44 +00:00
} catch (error) {
await interaction.reply({ content: "Sorry! Could not execute the clear command. Something went wrong", ephemeral: true });
2024-05-11 06:55:44 +00:00
console.log(errorStatus + "Something went wrong while trying to clear messages! Debug information is below.");
console.error(error);
}
}
}