JDA编辑EmbedBuilder字段:HP计数器

JDA edit EmbedBuilder field: HP counter

我想编辑我的 EmbedBuilder:我正在尝试创建一个健康点计数器,但我不知道如何编辑相同的字段。现在它只是创建新的字段,所以 EmbedBuilder 充满了 HP 计数器...

            EmbedBuilder fight = new EmbedBuilder();
            fight.setTitle("Battle");

            MessageEmbed embed = fight.build();

event.getChannel().sendMessage(embed).queue(message -> {

                int user1HP = 100;
                int user2HP = 100;
                int i = 1;

                while (user2HP > 0 && user1HP > 0) {
                    Random randomValue = new Random();
                    int dmg = randomValue.nextInt((25 - 1) + 1) + 1;
                    String damage;
                    fight.addField("HP1: ", ""+user1HP, true); //How can I edit this and not create other fields?
                    fight.addField("HP2: ", ""+user2HP, true);
                    message.editMessage(fight.build()).queue();


                    if ((i%2)==0) {

                        i=i+1;
                        System.out.println(i);

                        damage = "A inflicted " + dmg + " to B";

                        System.out.println(damage);

                        user2HP = user2HP - dmg;




                    } else {

                        i=i+1;
                        System.out.println(i);

                        damage = "B inflicted " + dmg + " to A";

                        System.out.println(damage);

                        user1HP = user1HP - dmg;

                    }
                }
            });

您可以使用 getFields() 获取字段列表并使用 set(index, Field):

修改它
List<Field> fields = figet.getFields();

if (fields.size() > 0) {
  fight.addField("HP1:", String.valueOf(user1HP), true);
  fight.addField("HP1:", String.valueOf(user1HP), true);
} else {
  // update fields
  fields.set(0, new Field("HP1:", String.valueOf(user1HP), true));
  fields.set(1, new Field("HP2:", String.valueOf(user2HP), true));
}