diff --git a/src/main/java/xyz/srnyx/lazylibrary/LazyEmbed.java b/src/main/java/xyz/srnyx/lazylibrary/LazyEmbed.java index 0ef1626..cb3442a 100644 --- a/src/main/java/xyz/srnyx/lazylibrary/LazyEmbed.java +++ b/src/main/java/xyz/srnyx/lazylibrary/LazyEmbed.java @@ -655,6 +655,34 @@ public List getFields() { return Collections.unmodifiableList(fields); } + /** + * Returns a field from the embed by its name + * + * @param name the name of the field + * + * @return the field, or {@link Optional#empty() empty} if not found + */ + @NotNull + public Optional getField(@NotNull String name) { + for (final MessageEmbed.Field field : fields) { + final String fieldName = field.getName(); + if (fieldName != null && fieldName.equals(name)) return Optional.of(field); + } + return Optional.empty(); + } + + /** + * Returns the value of a field from the embed by its name + * + * @param name the name of the field + * + * @return the value of the field, or {@link Optional#empty() empty} if not found + */ + @NotNull + public Optional getFieldValue(@NotNull String name) { + return getField(name).map(MessageEmbed.Field::getValue); + } + /** * Clears all fields from the embed *