From 472820900299f3eecd852d9378cc86d77e7ee626 Mon Sep 17 00:00:00 2001 From: Keyemail Date: Sat, 11 May 2024 14:57:50 -0700 Subject: [PATCH] Clear command patches and new npm packages --- commands/moderation/clear.js | 16 +++++++++++++--- package-lock.json | 14 +++++++++++++- package.json | 4 +++- 3 files changed, 29 insertions(+), 5 deletions(-) diff --git a/commands/moderation/clear.js b/commands/moderation/clear.js index d24df56..3d388d4 100644 --- a/commands/moderation/clear.js +++ b/commands/moderation/clear.js @@ -1,9 +1,11 @@ -const { SlashCommandBuilder } = require('discord.js'); +const { SlashCommandBuilder, PermissionsBitField } = require('discord.js'); const informationStatus = "[INFO]: "; const warningStatus = "[WARNING]: "; const errorStatus = "[ERROR]: "; +const wait = require('node:timers/promises').setTimeout; + module.exports = { data: new SlashCommandBuilder() .setName('clear') @@ -15,12 +17,20 @@ module.exports = { async execute(interaction) { const amount = interaction.options.getNumber('amount'); - if(amount == isNaN() && amount <= 0) return interaction.channel.message('<:xmark:1238738768563933244> This is not a valid number!'); + if(amount <= 0) return interaction.reply({ content: "<:xmark:1238963594758979736> This is not a valid number!", ephemeral: true }); + + if(!interaction.member.permissions.has(PermissionsBitField.Flags.ManageMessages)) return interaction.reply({ content: "<:xmark:1238963594758979736> You dont have permission to use this command", ephemeral: true }); try { await interaction.channel.bulkDelete(amount); - interaction.channel.send(`<:checkmark:1238736677942460438> Deleted ${amount} of messages!`); + 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); + await interaction.deleteReply(); } catch (error) { + await interaction.reply({ content: "Sorry! Could not execute the clear command. Something went wrong", ephemeral: true }); console.log(errorStatus + "Something went wrong while trying to clear messages! Debug information is below."); console.error(error); } diff --git a/package-lock.json b/package-lock.json index c2f9571..3bf2732 100644 --- a/package-lock.json +++ b/package-lock.json @@ -11,7 +11,9 @@ "dependencies": { "discord.js": "^14.15.2", "fs": "^0.0.1-security", - "path": "^0.12.7" + "path": "^0.12.7", + "promises": "^0.2.5", + "timers": "^0.1.1" } }, "node_modules/@discordjs/builders": { @@ -265,6 +267,16 @@ "node": ">= 0.6.0" } }, + "node_modules/promises": { + "version": "0.2.5", + "resolved": "https://registry.npmjs.org/promises/-/promises-0.2.5.tgz", + "integrity": "sha512-KHTer6YK1+aD2AcLiRuE3/ilZzw1UoX8v6DuTlDdF0oc5uOZlyWA+x2JwaO0bPB+E/JiRiUQmjfuNXiWlVD2tQ==" + }, + "node_modules/timers": { + "version": "0.1.1", + "resolved": "https://registry.npmjs.org/timers/-/timers-0.1.1.tgz", + "integrity": "sha512-pkJC8uIP/gxDHxNQUBUbjHyl6oZfT+ofn7tbaHW+CFIUjI+Q2MBbHcx1JSBQfhDaTcO9bNg328q0i7Vk5PismQ==" + }, "node_modules/ts-mixer": { "version": "6.0.4", "resolved": "https://registry.npmjs.org/ts-mixer/-/ts-mixer-6.0.4.tgz", diff --git a/package.json b/package.json index 04461e4..eedc408 100644 --- a/package.json +++ b/package.json @@ -23,6 +23,8 @@ "dependencies": { "discord.js": "^14.15.2", "fs": "^0.0.1-security", - "path": "^0.12.7" + "path": "^0.12.7", + "promises": "^0.2.5", + "timers": "^0.1.1" } }