Skip to content

Commit

Permalink
bug fixes?
Browse files Browse the repository at this point in the history
  • Loading branch information
eYuM-coder committed Oct 9, 2024
1 parent 1c8a623 commit 5180afd
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 28 deletions.
15 changes: 10 additions & 5 deletions src/commands/moderation/clear.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ module.exports = class extends Command {
try {
const logging = await Logging.findOne({ guildId: message.guild.id });

if (logging.moderation.delete_after_executed === "true") {
message.delete().catch(() => { });
}

const client = message.client;
const fail = client.emoji.fail;
const success = client.emoji.success;
Expand Down Expand Up @@ -57,10 +61,6 @@ module.exports = class extends Command {
reason = reason.slice(0, 1021) + "...";
}

if (logging.moderation.delete_after_executed === "true") {
message.delete().catch(() => { });
}

let messages;
messages = amount;

Expand All @@ -72,11 +72,16 @@ module.exports = class extends Command {
const deletedMessages = await channel.bulkDelete(messagesToDelete, true);
totalDeleted += deletedMessages.size;
logger.info(`Deleted ${deletedMessages.size} ${deletedMessages.size === 1 ? "message" : "messages"}.`, { label: "Purge" });
if (deletedMessages.size === 0) {
break;
} else if (deletedMessages.size < 100) {
continue;
}
} catch (error) {
logger.info(`Error deleting messages: ${error}`, { label: "ERROR" });
return message.channel.send({ content: "There was an error trying to delete messages in this channel." });
}
setTimeout(() => { }, 10000);
setTimeout(() => { }, 30000);
}

const embed = new MessageEmbed()
Expand Down
41 changes: 18 additions & 23 deletions src/slashCommands/moderation/clear.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
const { SlashCommandBuilder } = require("@discordjs/builders");
const { MessageEmbed } = require("discord.js");
const Logging = require("../../database/schemas/logging.js");
const logger = require("../../utils/logger.js");

module.exports = {
data: new SlashCommandBuilder()
Expand Down Expand Up @@ -63,35 +64,28 @@ module.exports = {
try {
const deletedMessages = await channel.bulkDelete(messagesToDelete, true);
totalDeleted += deletedMessages.size;
if (deletedMessages.size === 0) {
break;
} else if (deletedMessages.size < 100) {
continue;
}
} catch (error) {
return interaction.editReply({ content: "There was an error trying to delete messages in this channel.", ephemeral: true });
}
setTimeout(() => { }, 30000)
}

if (totalDeleted === 0) {
interaction.editReply({
embeds: [
new MessageEmbed()
.setDescription(
`
${fail} | Unable to find any messages.
`,
)
.setColor(interaction.client.color.red),
],
ephemeral: true,
});
} else {
const embed = new MessageEmbed()

.setDescription(
`${success} | ***Successfully deleted ${totalDeleted} ${totalDeleted === 1 ? "message" : "messages"}.* || ${reason}**`,
)
const embed = new MessageEmbed()

.setColor(interaction.client.color.green);
.setDescription(
`${success} | ***Successfully deleted ${totalDeleted} ${totalDeleted === 1 ? "message" : "messages"}.* || ${reason}**`,
)

.setColor(interaction.client.color.green);

interaction.editReply({ embeds: [embed], ephemeral: true });

interaction.editReply({ embeds: [embed], ephemeral: true });
}

if (logging) {
const role = interaction.guild.roles.cache.get(
Expand Down Expand Up @@ -128,17 +122,18 @@ module.exports = {
.setFooter({ text: `Responsible ID: ${interaction.member.id}` })
.setColor(color);

loggingChannel.send({ embeds: [logEmbed] }).catch(() => {});
loggingChannel.send({ embeds: [logEmbed] }).catch(() => { });

logging.moderation.caseN = logcase + 1;
await logging.save().catch(() => {});
await logging.save().catch(() => { });
}
}
}
}
}
}
} catch (err) {
logger.info(`An error occurred: ${err}`, { label: "ERROR" });
interaction.reply({
content: "This command cannot be used in Direct Messages.",
ephemeral: true,
Expand Down

0 comments on commit 5180afd

Please sign in to comment.