(JDA) 静音命令在代码的第四行中断

(JDA) Mute command is breaking at the fourth line of the code

String[] messageSent = event.getMessage().getContentRaw().split("\s+");
if (messageSent[0].equalsIgnoreCase("/mute")) {
            if (messageSent.length == 2) {
                Member member = event.getGuild().getMemberById(messageSent[1].replace("<@", "").replace(">", ""));
                Role role = event.getGuild().getRoleById("731166424608931900");

                if (!member.getRoles().contains(role)) {
                        //mute user
                    event.getChannel().sendMessage("Muted " + messageSent[1] + ".").queue();
                    event.getGuild().addRoleToMember(member, role);
                }else {
                    //unmute user
                    event.getChannel().sendMessage("Unmuted " + messageSent[1] + ".").queue();
                    event.getGuild().removeRoleFromMember(member, role);
                }

            }else if (messageSent.length == 3) {

            }else {
                event.getChannel().sendMessage("incorrect syntax i dont have time to make this error message pretty, fuck!").queue();
            }
        }

所以问题在于

1st:它可能在第四行中断又名 Member member = event.getGuild().getMemberById(messageSent[1].replace("<@", "").replace(">", ""));

第 2 次:我收到此错误 [JDA MainWS-ReadThread] ERROR JDA - One of the EventListeners had an uncaught exception java.lang.NullPointerException

  1. 您应该只使用 Message#getMentionedUsers 让 JDA 为您进行解析。

  2. 确保成员是 cached or use Guild#retrieveMemberById(或其他 retrieveMember* 方法之一)。

编辑:另请参阅疑难解答: Users/Members 不在缓存中