From 2790815ed7aecc00cd319e79be0b5763a0169fad Mon Sep 17 00:00:00 2001 From: Nathaniel Wood Date: Tue, 8 Oct 2024 14:01:07 -0600 Subject: [PATCH] Update: Some small little changes --- src/commands/moderation/clear.js | 29 ++++++--------------------- src/data/emoji.js | 8 ++++---- src/events/message/messageCreate.js | 4 ++-- src/slashCommands/moderation/clear.js | 19 ++++++++---------- 4 files changed, 20 insertions(+), 40 deletions(-) diff --git a/src/commands/moderation/clear.js b/src/commands/moderation/clear.js index a8d6a73..c18e7e3 100644 --- a/src/commands/moderation/clear.js +++ b/src/commands/moderation/clear.js @@ -1,20 +1,20 @@ const Command = require("../../structures/Command"); const { MessageEmbed } = require("discord.js"); const Logging = require("../../database/schemas/logging.js"); +const logger = require("../../utils/logger.js"); module.exports = class extends Command { constructor(...args) { super(...args, { name: "clear", aliases: ["cls", "purge"], - description: " Delete the specified amount of messages", + description: "Delete the specified amount of messages", category: "Moderation", usage: "purge [reason]", examples: [ "purge 20", - "purge #general 10", - "purge @peter 50", - "purge #general @peter 5", + "cls 50", + "clear 125" ], guildOnly: true, botPermission: ["MANAGE_MESSAGES"], @@ -57,8 +57,6 @@ module.exports = class extends Command { reason = reason.slice(0, 1021) + "..."; } - await message.delete(); - let messages; messages = amount; @@ -149,26 +147,11 @@ module.exports = class extends Command { } } } - } catch { + } catch (error) { + logger.info(`An error occurred: ${error}`, { label: "ERROR" }); return message.channel.sendCustom( `${message.client.emoji.fail} | Could not purge messages` ); } } }; - -function getMemberFromMention(message, mention) { - if (!mention) return; - const matches = mention.match(/^<@!?(\d+)>$/); - if (!matches) return; - const id = matches[1]; - return message.guild.members.cache.get(id); -} - -function getChannelFromMention(message, mention) { - if (!mention) return; - const matches = mention.match(/^<#(\d+)>$/); - if (!matches) return; - const id = matches[1]; - return message.guild.channels.cache.get(id); -} diff --git a/src/data/emoji.js b/src/data/emoji.js index 782187f..2b76cd1 100644 --- a/src/data/emoji.js +++ b/src/data/emoji.js @@ -1,7 +1,7 @@ module.exports = { - x: "<:wrong:822379358453891123>", - fail: "<:wrong:822379358453891123> ", - check: "<:success:1159255004817932398> ", - success: "<:success:1159255004817932398> ", + x: "<:fail:1293235307998740480>", + fail: "<:fail:1293235307998740480>", + check: "<:success:1293235164662595756>", + success: "<:success:1293235164662595756>", cash: "$", }; diff --git a/src/events/message/messageCreate.js b/src/events/message/messageCreate.js index 5a917fd..55aa6e6 100644 --- a/src/events/message/messageCreate.js +++ b/src/events/message/messageCreate.js @@ -219,7 +219,7 @@ module.exports = class extends Event { `${this.client.user.tag}`, message.client.user.displayAvatarURL({ dynamic: true }), ) - .setTitle(`<:wrong:822376943763980348> Missing Bot Permissions`) + .setTitle(`<:fail:1293235307998740480> Missing Bot Permissions`) .setDescription( `Command Name: **${ command.name @@ -245,7 +245,7 @@ module.exports = class extends Event { `${message.author.tag}`, message.author.displayAvatarURL({ dynamic: true }), ) - .setTitle(`<:wrong:822376943763980348> Missing User Permissions`) + .setTitle(`<:fail:1293235307998740480> Missing User Permissions`) .setDescription( `Command Name: **${ command.name diff --git a/src/slashCommands/moderation/clear.js b/src/slashCommands/moderation/clear.js index d2bbc46..a3e3ac4 100644 --- a/src/slashCommands/moderation/clear.js +++ b/src/slashCommands/moderation/clear.js @@ -2,13 +2,12 @@ const { SlashCommandBuilder } = require("@discordjs/builders"); const { MessageEmbed } = require("discord.js"); const Logging = require("../../database/schemas/logging.js"); const logger = require("../../utils/logger.js"); -let messageDisplay = "messages"; module.exports = { data: new SlashCommandBuilder() .setName("clear") .setDescription("Purges a channels messages") - .addIntegerOption((option) => + .addStringOption((option) => option .setName("amount") .setDescription("Amount of messages to clear") @@ -26,17 +25,17 @@ module.exports = { const fail = client.emoji.fail; const success = client.emoji.success; - const amount = interaction.options.getInteger("amount"); + const amount = parseInt(interaction.options.getString("amount")); const channel = interaction.channel; const reason = interaction.options.getString("reason"); if (!reason) { - reason = "None"; + reason = "No reason provided."; } if (reason.length > 1024) { reason = reason.slice(0, 1021) + "..."; } - if (amount < 0 || amount > 200) { + if (isNaN(amount) || amount < 0 || amount > 200) { let invalidamount = new MessageEmbed() .setAuthor({ name: `${interaction.user.tag}`, @@ -86,17 +85,15 @@ module.exports = { ephemeral: true, }); } else { - channel.bulkDelete(messages, true).then((messages) => { const embed = new MessageEmbed() .setDescription( - `${success} | ***Successfully deleted ${totalDeleted} ${totalDeleted === 1 ? "message" : "messages"}* || ${reason}**`, + `${success} | ***Successfully deleted ${totalDeleted} ${totalDeleted === 1 ? "message" : "messages"}.* || ${reason}**`, ) .setColor(interaction.client.color.green); interaction.editReply({ embeds: [embed], ephemeral: true }); - }); } if (logging) { @@ -127,11 +124,11 @@ module.exports = { const logEmbed = new MessageEmbed() .setAuthor( `Action: \`Purge\` | Case #${logcase}`, - message.author.displayAvatarURL({ format: "png" }) + interaction.member.displayAvatarURL({ format: "png" }) ) - .addField("Moderator", `${interaction.user}`, true) + .addField("Moderator", `${interaction.member}`, true) .setTimestamp() - .setFooter({ text: `Responsible ID: ${interaction.user.id}` }) + .setFooter({ text: `Responsible ID: ${interaction.member.id}` }) .setColor(color); loggingChannel.send({ embeds: [logEmbed] }).catch(() => {});