2021-09-06 12:38:25 +02:00
|
|
|
const { MessageEmbed } = require("discord.js");
|
|
|
|
|
|
|
|
module.exports = {
|
|
|
|
name: "clear",
|
|
|
|
description: "Clear messages in a specific channel",
|
|
|
|
options: [
|
|
|
|
{
|
2021-11-18 18:56:42 +01:00
|
|
|
name: "channel",
|
2021-09-06 12:38:25 +02:00
|
|
|
description: "Channel where the messages to be deleted",
|
2021-11-18 18:56:42 +01:00
|
|
|
type: 7,
|
2021-09-06 12:38:25 +02:00
|
|
|
required: true,
|
2021-11-18 18:56:42 +01:00
|
|
|
channelTypes: ["GUILD_TEXT"],
|
2021-09-06 12:38:25 +02:00
|
|
|
},
|
|
|
|
{
|
2021-11-18 18:56:42 +01:00
|
|
|
name: "amount",
|
2021-09-06 12:38:25 +02:00
|
|
|
description: "Amount of message in range of 1-100 to be deleted",
|
2021-11-18 18:56:42 +01:00
|
|
|
type: 4,
|
2021-09-06 12:38:25 +02:00
|
|
|
required: true,
|
|
|
|
},
|
|
|
|
],
|
|
|
|
type: "CHAT_INPUT",
|
|
|
|
run: async (client, interaction, args) => {
|
2021-09-17 18:28:39 +02:00
|
|
|
try {
|
2021-11-18 18:56:42 +01:00
|
|
|
const query = args[1];
|
|
|
|
const channel = interaction.guild.channels.cache.get(args[0]);
|
|
|
|
if (query > 100) {
|
2021-09-17 18:28:39 +02:00
|
|
|
return interaction.followUp({
|
|
|
|
content: "The amount of messages must be in range of 1-100",
|
|
|
|
});
|
|
|
|
}
|
|
|
|
if (channel.type !== "GUILD_TEXT") {
|
|
|
|
return interaction.followUp({
|
2021-09-21 01:51:56 +02:00
|
|
|
content: "Please provide a text channel",
|
2021-09-17 18:28:39 +02:00
|
|
|
});
|
|
|
|
}
|
|
|
|
const limit = await interaction.channel.messages.fetch({
|
2021-11-18 18:56:42 +01:00
|
|
|
limit: query,
|
2021-09-06 12:38:25 +02:00
|
|
|
});
|
2021-09-17 18:28:39 +02:00
|
|
|
await channel.bulkDelete(limit, true).then(async m => {
|
|
|
|
const results = {};
|
|
|
|
for (const [, deleted] of m) {
|
|
|
|
const user = `${deleted.author.username}#${deleted.author.discriminator}`;
|
|
|
|
if (!results[user]) results[user] = 0;
|
|
|
|
results[user]++;
|
|
|
|
}
|
|
|
|
const userMessageMap = Object.entries(results);
|
|
|
|
channel.send({
|
|
|
|
embeds: [
|
|
|
|
new MessageEmbed()
|
|
|
|
.setTitle(`Message Cleared`)
|
|
|
|
.addField(
|
|
|
|
"**Moderator**",
|
|
|
|
`${
|
|
|
|
interaction.member.nickname
|
|
|
|
? interaction.member.nickname
|
|
|
|
: interaction.user.username
|
|
|
|
}`,
|
|
|
|
true
|
|
|
|
)
|
2021-11-18 18:56:42 +01:00
|
|
|
.addField("Amount of Message Deleted", `${m.size}/${query}`, true)
|
2021-09-17 18:28:39 +02:00
|
|
|
.addField(
|
|
|
|
"Authors",
|
|
|
|
`${userMessageMap
|
|
|
|
.map(([user, messages]) => `**${user}** : ${messages}`)
|
|
|
|
.join("\n")}`,
|
|
|
|
false
|
|
|
|
)
|
|
|
|
.setFooter(
|
2021-11-18 18:56:42 +01:00
|
|
|
`Made by ${client.author}`,
|
|
|
|
client.user.displayAvatarURL()
|
|
|
|
)
|
|
|
|
.setTimestamp()
|
|
|
|
.setThumbnail(
|
2021-09-17 18:28:39 +02:00
|
|
|
interaction.user.displayAvatarURL({ dynamic: true })
|
|
|
|
)
|
|
|
|
.setColor(client.color),
|
|
|
|
],
|
|
|
|
});
|
2021-09-06 12:38:25 +02:00
|
|
|
});
|
2021-09-17 18:28:39 +02:00
|
|
|
} catch (e) {
|
|
|
|
console.log(e);
|
2021-11-18 18:56:42 +01:00
|
|
|
interaction.followUp({ content: `**Error**: ${e.message}` });
|
2021-09-17 18:28:39 +02:00
|
|
|
}
|
2021-09-06 12:38:25 +02:00
|
|
|
},
|
|
|
|
};
|