const Discord = module.require("discord.js");
const fs = require("fs");
module.exports.run = async (bot,message,args) => {
try{
if(!message.member.hasPermission("MANAGE_MESSAGES")) return message.channel.send("У вас нет прав");
if(args[0]>100) return bot.send("Укажите значение меньше 100");
if(args[0]<1) return bot.send("Укажите значение больше 1");
message.channel.bulkDelete(args[0]).then(() =>{
message.channel.send(`Удалено ${args[0]} сообщений`).then(msg => msg.delete(15*1000));
});
bot.send(botmessage);
}catch(err){
console.log(err.name)
}
};
module.exports.help = {
name: "clear"
};
public class ClearCommand extends ListenerAdapter implements ICommand {
public void onGuildMessageReceived(GuildMessageReceivedEvent event) {
String[] args = event.getMessage().getContentRaw().split("\\s+");
if (args[0].equalsIgnoreCase(Config.get("prefix") + "clear")) {
if (args.length < 2) {
// Usage
EmbedBuilder usage = new EmbedBuilder();
usage.setColor(0xff3923);
usage.setTitle("Specify amount to delete");
usage.setDescription("Usage: `" +"ваш префикс" + "clear [# of messages]`");
event.getChannel().sendMessage(usage.build()).queue();
}
else {
try {
List<Message> messages = event.getChannel().getHistory().retrievePast(Integer.parseInt(args[1])).complete();
event.getChannel().deleteMessages(messages).queue();
// Success
EmbedBuilder success = new EmbedBuilder();
success.setColor(0x22ff2a);
success.setTitle("✅ Successfully deleted " + args[1] + " messages.");
event.getChannel().sendMessage(success.build()).queue();
}
catch (IllegalArgumentException e) {
if (e.toString().startsWith("java.lang.IllegalArgumentException: Message retrieval")) {
// Too many messages
EmbedBuilder error = new EmbedBuilder();
error.setColor(0xff3923);
error.setTitle(" Too many messages selected");
error.setDescription("Between 1-100 messages can be deleted at one time.");
event.getChannel().sendMessage(error.build()).queue();
}
else {
// Messages too old
EmbedBuilder error = new EmbedBuilder();
error.setColor(0xff3923);
error.setTitle(" Selected messages are older than 2 weeks");
error.setDescription("Messages older than 2 weeks cannot be deleted.");
event.getChannel().sendMessage(error.build()).queue();
}
}
}
}
}
}