Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const { MessageEmbed } = require("discord.js")
- const config = require('../config.json')
- module.exports = {
- name: 'clear',
- description: 'Clear message from a channel.',
- async execute(message, args, bot, config, log) {
- const logCh = bot.channels.cache.get('843563922844811264')
- require('discord-reply');
- if (!message.member.permissions.has("MANAGE_MESSAGES")) return message.channel.send('You cannot use this command.');
- if (!message.guild.me.permissions.has("MANAGE_MESSAGES")) return message.channel.send('I dont have the correct permissions to do this command.');
- if (!args[0]) return message.channel.send('Please provide a number of messages to clear.');
- const amt = Number(args[0], 10);
- if (isNaN(amt)) return message.channel.send('Please provide a valid number.');
- if (!Number.isInteger(amt)) return message.channel.send('Please provide a whole number.')
- if (!amt || amt < 2 || amt > 100) return message.channel.send('Please preovide a number between 2 and 100.')
- const fetched = await message.channel.messages.fetch({
- limit: amt
- });
- try {
- await message.channel.bulkDelete(fetched)
- .then(
- message.channel.startTyping(),
- setTimeout(function() {
- message.channel.stopTyping();
- message.channel.send(`Successfully deleted ${amt} messages.`);
- }, 10)
- )
- } catch (err) {
- console.error(err);
- await message.lineReply('I was unable to delete the amount stated.')
- }
- logCh.send(new MessageEmbed()
- .setTitle("Messages Cleared")
- .setDescription(`**${amt}** messages has been cleared from <#${message.channel.id}>`)
- .setColor("RED")
- )
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment