#Discord JDA #clear/purge 命令,为什么我的清除以前消息的代码没有按预期工作?

#Discord JDA #clear/purge command, Why is my code that will clear previous messages not working as intended?

我是 Discord JDA 的新手 API,我被这个问题困住了。每当我 运行 这段用于“清除”命令的代码时,机器人只显示 error1 消息。即使我在 !purge 后面加上“!purge 23”之类的数字,机器人也没有响应。我究竟做错了什么?我多年来一直坚持这一点。任何帮助将不胜感激!

public void onMessageReceived(MessageReceivedEvent event) {
    String[] args = event.getMessage().getContentRaw().split("//s+");
    if(args[0].equalsIgnoreCase(Bot.prefix + "purge")) {
        if (args.length < 2) {
            EmbedBuilder error1 = new EmbedBuilder();
            error1.setColor(Color.RED);
            error1.setTitle("❌ Specify # of messages to delete!");
            error1.setDescription("Usage: " + Bot.prefix + "purge [# of messages]");
            event.getChannel().sendTyping().queue();
            event.getChannel().sendMessage(error1.build()).queue(m -> 
            m.delete().queueAfter(5, TimeUnit.SECONDS));
        }
        
        else if(Integer.parseInt(args[1]) > 100 || Integer.parseInt(args[1]) < 1) {
            EmbedBuilder error2 = new EmbedBuilder();
            error2.setColor(Color.RED);
            error2.setTitle("❌ Only 1-100 messages can be deleted!");
            error2.setDescription("Usage: " + Bot.prefix + "clear [1-100]");
            event.getChannel().sendMessage(error2.build()).queue(m -> 
            m.delete().queueAfter(5, TimeUnit.SECONDS));
        }
        
        else if(Integer.parseInt(args[1]) < 100 && Integer.parseInt(args[1]) > 1){
            int values = Integer.parseInt(args[1]);
            event.getMessage().delete();
            List<Message> messages = event.getChannel().getHistory().retrievePast(values).complete();
            event.getTextChannel().deleteMessages(messages).queue();
            event.getChannel().sendMessage("✅ " + args[1].toString() + " messages 
            deleted!").queue(m -> 
            m.delete().queueAfter(5, TimeUnit.SECONDS));
        }
    }
}

}

你的拆分正则表达式是错误的。你做了 "//s+" 但你应该做 "\s+".