From de73e06a5b189f222ea0df266c6ca88eb1b0decd Mon Sep 17 00:00:00 2001 From: WubzyGD Date: Fri, 7 May 2021 18:17:35 -0600 Subject: [PATCH] n?delete (unstable) --- commands/moderation/delete.js | 38 +++++++++++++++++++++++++++++++++++ commands/utility/todo.js | 3 ++- 2 files changed, 40 insertions(+), 1 deletion(-) create mode 100644 commands/moderation/delete.js diff --git a/commands/moderation/delete.js b/commands/moderation/delete.js new file mode 100644 index 0000000..fe70f75 --- /dev/null +++ b/commands/moderation/delete.js @@ -0,0 +1,38 @@ +const Discord = require('discord.js'); + +module.exports = { + name: "delete", + aliases: ['del', 'purge', 'clear'], + meta: { + category: 'Moderation', + description: "Delete messages from a channel, and optionally from a specific user or users.", + syntax: '`clear [@user] [@user] [etc]`', + extra: null, + guildOnly: true + }, + help: new Discord.MessageEmbed() + .setTitle("Help -> Mass Message Deletion") + .setDescription("Delete recently-sent messages from a channel. You can also delete them from a specific user or users, if you wish.") + .addField("Permissions", "You must have Manage Messages permissions in this server in order to purge messages.") + .addField("Mentions", "If you mention multiple people, I will delete messages from those users until the total sum of messages reaches the specified message count. In other words, if you mention three people and specify to delete 6 messages, I will the last 6 messages from all of them, not the last 6 messages for each user.") + .addField("Notice", "Purges with mentions might purge less than the specified count. This only really affects large deletion counts in channels where several other people than just the members mentioned talked. A fix is currently being made.") + .addField("Syntax", "`clear [@user] [@user] [etc]`"), + async execute(message, msg, args, cmd, prefix, mention, client) { + if (!message.member.permissions.has("MANAGE_MESSAGES")) {return message.channel.send("You don't have permissions to manage messages in this server!");} + if (!args.length) {return message.channel.send(`Syntax: \`${prefix}clear [@user] [@user] [etc]\``);} + if (!message.guild.me.permissions.has("MANAGE_MESSAGES")) {return message.channel.send("I don't have permissions to manage messages in this server.");} + if (!message.channel.permissionsFor(client.user.id).has("MANAGE_MESSAGES")) {return message.channel.send("I don't have permissions to manage messages in this channel.");} + if (isNaN(Number(args[0])) || Number(args[0]) > 100 || Number(args[0]) < 1) {return message.channel.send("You must specify a positive number less than 100 of messages to delete.");} + await message.delete(); + let count = Number(args[0]); + while (true) { + let messages = await message.channel.messages.fetch({limit: message.mentions.users.size ? 50 : count}, false, true).catch(() => message.channel.send("There was an error trying to grab the messages to delete. Sorry!")); + let toDelete = []; + if (message.mentions.users.size) {Array.from(message.mentions.users.values()).forEach(u => Array.from(messages.values()).forEach(m => {if (m.author.id === u.id && toDelete.length < count) {toDelete.push(m.id);}}));} + else {toDelete = Array.from(messages.keys());} + await message.channel.bulkDelete(toDelete, true); + if (toDelete.length >= count) {break;} + } + return true; + } +}; \ No newline at end of file diff --git a/commands/utility/todo.js b/commands/utility/todo.js index 00b945c..1cff85b 100644 --- a/commands/utility/todo.js +++ b/commands/utility/todo.js @@ -140,7 +140,8 @@ module.exports = { .setTimestamp() ).catch(() => { client.users.fetch(client.developers[0]).then(wubzy => wubzy.send("Hey stupid, someone got the todo length bug. Fix it.")); - return message.channel.send("There was an error displaying your list. It might have too many characters. This bug has been reported to the developers and will be fixed soon! Join the support server for updates.");}); + return message.channel.send("There was an error displaying your list. It might have too many characters. This bug has been reported to the developers and will be fixed soon! Join the support server for updates."); + }); } else { if (isNaN(Number(args[1])) && !['last', 'l'].includes(args[1].toLowerCase().trim())) {return message.channel.send("You didn't give me a number!");} let id = ['last', 'l'].includes(args[1].toLowerCase().trim()) ? td.lists[list].length : Number(args[1]);