Search in sources :

Example 1 with MessageHistory

use of net.dv8tion.jda.api.entities.MessageHistory in project c0debaseBot by Biospheere.

the class ClearCommand method execute.

@Override
public void execute(final String[] args, final Message message) {
    if (args.length == 0) {
        final EmbedBuilder embedBuilder = getEmbed(message.getMember());
        embedBuilder.appendDescription("!clear <Amount>");
        message.getTextChannel().sendMessage(embedBuilder.build()).queue();
    } else {
        int i = 0;
        try {
            i = Integer.valueOf(args[0]);
        } catch (NumberFormatException ex) {
            ex.printStackTrace();
        }
        final MessageHistory history = new MessageHistory(message.getTextChannel());
        final List<Message> messages = history.retrievePast(i + 1).complete();
        message.getTextChannel().deleteMessages(messages).queue();
        final EmbedBuilder embedBuilder = DiscordUtils.getDefaultEmbed(message.getMember());
        embedBuilder.setColor(message.getGuild().getSelfMember().getColor());
        embedBuilder.appendDescription("Es wurden **" + (i) + "** Nachrichten gelöscht");
        message.getTextChannel().sendMessage(embedBuilder.build()).queue();
    }
}
Also used : MessageHistory(net.dv8tion.jda.api.entities.MessageHistory) EmbedBuilder(net.dv8tion.jda.api.EmbedBuilder) Message(net.dv8tion.jda.api.entities.Message)

Aggregations

EmbedBuilder (net.dv8tion.jda.api.EmbedBuilder)1 Message (net.dv8tion.jda.api.entities.Message)1 MessageHistory (net.dv8tion.jda.api.entities.MessageHistory)1