src/main/java/me/evyn/bot/commands/moderation/Kick.java
@Override
    public void run(MessageReceivedEvent event, String prefix, boolean embed, String[] args) {

        User botUser = event.getJDA().getSelfUser();

        // if command is not ran in guild, send error and return
        if (!event.isFromType(ChannelType.TEXT)) {
            EmbedBuilder eb = EmbedCreator.newErrorEmbedMessage(botUser, "This command can only be ran in servers.");

            event.getChannel()
                    .sendMessage(eb.build())
                    .queue();
            return;
        }

        Member botMember = event.getGuild().getSelfMember();

        EmbedBuilder eb = null;
        String message = "";

        // if Bot does not have Kick Members permission
        if (!botMember.hasPermission(Permission.KICK_MEMBERS)) {
            String desc = "The bot is missing permission `Kick Members`";
            if (embed) {
                eb = EmbedCreator.newErrorEmbedMessage(botUser, desc);
            } else {
                message = "ERROR: " + desc;
            }

        } else {

            // if User does not have Kick Members permission
            if (!event.getMember().hasPermission(Permission.KICK_MEMBERS)) {
                String desc = "You are missing permission `Kick Members`";
                if (embed) {
                    eb = EmbedCreator.newErrorEmbedMessage(botUser,desc);
                } else {
                    message = "ERROR: " + desc;
                }

            } else {

                // no user is provided
                if (args.length == 0) {
                    String desc = "No user was provided. For more information try running `" + prefix + "usage " +
                            "kick`";
                    if (embed) {
                        eb = EmbedCreator.newErrorEmbedMessage(botUser, desc);
                    } else {
                        message = "ERROR: " + desc;
                    }

                } else {

                    // fetch user Id
                    String Id = args[0].replaceAll("[^0-9.]", "");

                    try {
                        RestAction<Member> tempMember = event.getGuild().retrieveMemberById(Id);
                        Member providedMember = tempMember.complete();

                        eb = EmbedCreator.newCommandEmbedMessage(botUser);

                        if (embed) {
                            eb.setTitle("Kick");
                        }

                        StringBuilder sb = new StringBuilder();

                        // kick with reason
                        if (args.length > 1) {

                            for (int i = 1; i < args.length; i++) {
                                sb.append(args[i]).append(" ");
                            }

                            event.getGuild()
                                    .kick(providedMember, sb.toString())
                                    .queue();
                        } else {

                            // kick without reason
                            event.getGuild()
                                    .kick(providedMember)
                                    .queue();

                        }

                        String desc = "User `" + providedMember.getUser().getAsTag() + "` was kicked " +
                                "successfully.";
                        if (embed) {
                            eb.setDescription(desc);

                        } else {
                            message = desc;
                        }

                        TextChannel modLogs = ModLogs.getModLogChannel(event, event.getGuild().getIdLong());

                        if (modLogs != null) {
                            String logMessage = "**Action:** Kick" + "\n" + "**User:** " +
                                    providedMember.getUser().getAsTag() + " (" +
                                    providedMember.getUser().getId() + ") " + "\n" + "**Reason:** ";

                            if (sb.toString().equals("")) {
                                logMessage += "None";
                            } else {
                                logMessage += sb.toString();
                            }

                            logMessage += "\n" + "**Moderator:** " + event.getAuthor().getAsTag();

                            if (embed) {
                                EmbedBuilder modLog = new EmbedBuilder()
                                        .setDescription(logMessage)
                                        .setColor(0xffa500)
                                        .setTimestamp(Instant.now());

                                modLogs.sendMessage(modLog.build())
                                        .queue();
                            } else {
                                modLogs.sendMessage(logMessage)
                                        .queue();
                            }
                        }

                    } catch (HierarchyException e) {
                        String desc = "Provided user has the same or greater permission levels as the bot.";
                        if (embed) {
                            eb = EmbedCreator.newErrorEmbedMessage(botUser, desc);
                        } else {
                            message = "ERROR" + desc;
                        }
                    } catch (IllegalArgumentException | ErrorResponseException e) {
                        String desc = "Provided user is either invalid or is no longer in the server.";
                        if (embed) {
                            eb = EmbedCreator.newErrorEmbedMessage(botUser, desc);
                        } else {
                            message = "ERROR: " + desc;
                        }
                    }
                }
            }
        }

        // send message
        if (embed) {
            event.getChannel()
                .sendMessage(eb.build())
                .queue();
        } else {
            event.getChannel()
                    .sendMessage(message)
                    .queue();
        }
    }
/**
     * If command is ran in guild and bot + user have required permissions, kicks mentioned user with optional reason
     * @param event Discord API message event
     * @param prefix Specific guild bot prefix
     * @param embed Guild embed setting
     * @param args Command arguments
     */
If command is ran in guild and bot + user have required permissions, kicks mentioned user with optional reason
@param event Discord API message event
@param prefix Specific guild bot prefix
@param embed Guild embed setting
@param args Command arguments
If command is ran in guild and bot + user have required permissions kicks mentioned user with optional reason @param event Discord API message event @param prefix Specific guild bot prefix @param embed Guild embed setting @param args Command arguments
@Override
    public void run(MessageReceivedEvent event, String prefix, boolean embed, String[] args) {
        User botUser = event.getJDA().getSelfUser();
        if (!event.isFromType(ChannelType.TEXT)) {
            EmbedBuilder eb = EmbedCreator.newErrorEmbedMessage(botUser, "This command can only be ran in servers.");
            event.getChannel()
                    .sendMessage(eb.build())
                    .queue();
            return;
        }
        Member botMember = event.getGuild().getSelfMember();
        EmbedBuilder eb = null;
        String message = "";
        if (!botMember.hasPermission(Permission.KICK_MEMBERS)) {
            String desc = "The bot is missing permission `Kick Members`";
            if (embed) {
                eb = EmbedCreator.newErrorEmbedMessage(botUser, desc);
            } else {
                message = "ERROR: " + desc;
            }
        } else {
            if (!event.getMember().hasPermission(Permission.KICK_MEMBERS)) {
                String desc = "You are missing permission `Kick Members`";
                if (embed) {
                    eb = EmbedCreator.newErrorEmbedMessage(botUser,desc);
                } else {
                    message = "ERROR: " + desc;
                }
            } else {
                if (args.length == 0) {
                    String desc = "No user was provided. For more information try running `" + prefix + "usage " +
                            "kick`";
                    if (embed) {
                        eb = EmbedCreator.newErrorEmbedMessage(botUser, desc);
                    } else {
                        message = "ERROR: " + desc;
                    }
                } else {
                    String Id = args[0].replaceAll("[^0-9.]", "");
                    try {
                        RestAction<Member> tempMember = event.getGuild().retrieveMemberById(Id);
                        Member providedMember = tempMember.complete();
                        eb = EmbedCreator.newCommandEmbedMessage(botUser);
                        if (embed) {
                            eb.setTitle("Kick");
                        }
                        StringBuilder sb = new StringBuilder();
                        if (args.length > 1) {
                            for (int i = 1; i < args.length; i++) {
                                sb.append(args[i]).append(" ");
                            }
                            event.getGuild()
                                    .kick(providedMember, sb.toString())
                                    .queue();
                        } else {
                            event.getGuild()
                                    .kick(providedMember)
                                    .queue();
                        }
                        String desc = "User `" + providedMember.getUser().getAsTag() + "` was kicked " +
                                "successfully.";
                        if (embed) {
                            eb.setDescription(desc);
                        } else {
                            message = desc;
                        }
                        TextChannel modLogs = ModLogs.getModLogChannel(event, event.getGuild().getIdLong());
                        if (modLogs != null) {
                            String logMessage = "**Action:** Kick" + "\n" + "**User:** " +
                                    providedMember.getUser().getAsTag() + " (" +
                                    providedMember.getUser().getId() + ") " + "\n" + "**Reason:** ";
                            if (sb.toString().equals("")) {
                                logMessage += "None";
                            } else {
                                logMessage += sb.toString();
                            }
                            logMessage += "\n" + "**Moderator:** " + event.getAuthor().getAsTag();
                            if (embed) {
                                EmbedBuilder modLog = new EmbedBuilder()
                                        .setDescription(logMessage)
                                        .setColor(0xffa500)
                                        .setTimestamp(Instant.now());
                                modLogs.sendMessage(modLog.build())
                                        .queue();
                            } else {
                                modLogs.sendMessage(logMessage)
                                        .queue();
                            }
                        }
                    } catch (HierarchyException e) {
                        String desc = "Provided user has the same or greater permission levels as the bot.";
                        if (embed) {
                            eb = EmbedCreator.newErrorEmbedMessage(botUser, desc);
                        } else {
                            message = "ERROR" + desc;
                        }
                    } catch (IllegalArgumentException | ErrorResponseException e) {
                        String desc = "Provided user is either invalid or is no longer in the server.";
                        if (embed) {
                            eb = EmbedCreator.newErrorEmbedMessage(botUser, desc);
                        } else {
                            message = "ERROR: " + desc;
                        }
                    }
                }
            }
        }
        if (embed) {
            event.getChannel()
                .sendMessage(eb.build())
                .queue();
        } else {
            event.getChannel()
                    .sendMessage(message)
                    .queue();
        }
    }
@ Override public void run ( MessageReceivedEvent event , String prefix , boolean embed , String [ ] args ) { User botUser = event . getJDA ( ) . getSelfUser ( ) ; if ( ! event . isFromType ( ChannelType . TEXT ) ) { EmbedBuilder eb = EmbedCreator . newErrorEmbedMessage ( botUser , "This command can only be ran in servers." ) ; event . getChannel ( ) . sendMessage ( eb . build ( ) ) . queue ( ) ; return ; } Member botMember = event . getGuild ( ) . getSelfMember ( ) ; EmbedBuilder eb = null ; String message = "" ; if ( ! botMember . hasPermission ( Permission . KICK_MEMBERS ) ) { String desc = "The bot is missing permission `Kick Members`" ; if ( embed ) { eb = EmbedCreator . newErrorEmbedMessage ( botUser , desc ) ; } else { message = "ERROR: " + desc ; } } else { if ( ! event . getMember ( ) . hasPermission ( Permission . KICK_MEMBERS ) ) { String desc = "You are missing permission `Kick Members`" ; if ( embed ) { eb = EmbedCreator . newErrorEmbedMessage ( botUser , desc ) ; } else { message = "ERROR: " + desc ; } } else { if ( args . length == 0 ) { String desc = "No user was provided. For more information try running `" + prefix + "usage " + "kick`" ; if ( embed ) { eb = EmbedCreator . newErrorEmbedMessage ( botUser , desc ) ; } else { message = "ERROR: " + desc ; } } else { String Id = args [ 0 ] . replaceAll ( "[^0-9.]" , "" ) ; try { RestAction < Member > tempMember = event . getGuild ( ) . retrieveMemberById ( Id ) ; Member providedMember = tempMember . complete ( ) ; eb = EmbedCreator . newCommandEmbedMessage ( botUser ) ; if ( embed ) { eb . setTitle ( "Kick" ) ; } StringBuilder sb = new StringBuilder ( ) ; if ( args . length > 1 ) { for ( int i = 1 ; i < args . length ; i ++ ) { sb . append ( args [ i ] ) . append ( " " ) ; } event . getGuild ( ) . kick ( providedMember , sb . toString ( ) ) . queue ( ) ; } else { event . getGuild ( ) . kick ( providedMember ) . queue ( ) ; } String desc = "User `" + providedMember . getUser ( ) . getAsTag ( ) + "` was kicked " + "successfully." ; if ( embed ) { eb . setDescription ( desc ) ; } else { message = desc ; } TextChannel modLogs = ModLogs . getModLogChannel ( event , event . getGuild ( ) . getIdLong ( ) ) ; if ( modLogs != null ) { String logMessage = "**Action:** Kick" + "\n" + "**User:** " + providedMember . getUser ( ) . getAsTag ( ) + " (" + providedMember . getUser ( ) . getId ( ) + ") " + "\n" + "**Reason:** " ; if ( sb . toString ( ) . equals ( "" ) ) { logMessage += "None" ; } else { logMessage += sb . toString ( ) ; } logMessage += "\n" + "**Moderator:** " + event . getAuthor ( ) . getAsTag ( ) ; if ( embed ) { EmbedBuilder modLog = new EmbedBuilder ( ) . setDescription ( logMessage ) . setColor ( 0xffa500 ) . setTimestamp ( Instant . now ( ) ) ; modLogs . sendMessage ( modLog . build ( ) ) . queue ( ) ; } else { modLogs . sendMessage ( logMessage ) . queue ( ) ; } } } catch ( HierarchyException e ) { String desc = "Provided user has the same or greater permission levels as the bot." ; if ( embed ) { eb = EmbedCreator . newErrorEmbedMessage ( botUser , desc ) ; } else { message = "ERROR" + desc ; } } catch ( IllegalArgumentException | ErrorResponseException e ) { String desc = "Provided user is either invalid or is no longer in the server." ; if ( embed ) { eb = EmbedCreator . newErrorEmbedMessage ( botUser , desc ) ; } else { message = "ERROR: " + desc ; } } } } } if ( embed ) { event . getChannel ( ) . sendMessage ( eb . build ( ) ) . queue ( ) ; } else { event . getChannel ( ) . sendMessage ( message ) . queue ( ) ; } }
If command is ran in guild and bot + user have required permissions, kicks mentioned user with optional reason
 @param event Discord API message event
 @param prefix Specific guild bot prefix
 @param embed Guild embed setting
 @param args Command arguments
If command is ran in guild and bot + user have required permissions kicks mentioned user with optional reason @param event Discord API message event @param prefix Specific guild bot prefix @param embed Guild embed setting @param args Command arguments
// if command is not ran in guild, send error and return // if Bot does not have Kick Members permission // if User does not have Kick Members permission // no user is provided // fetch user Id // kick with reason // kick without reason // send message