JDA icon indicating copy to clipboard operation
JDA copied to clipboard

Wrong expected type in jda docs

Open AveCard1nal opened this issue 7 months ago • 0 comments

General Troubleshooting

  • [x] I have checked for similar issues on the Issue-tracker.
  • [x] I have checked for PRs that might already address this issue.

Version of JDA

5.3.2

Expected Behaviour

Hi guys. Found a wrong expected type in AuditLogKey (MEMBER_ROLES_ADD and MEMBER_ROLES_REMOVE) in jda docs. So according to the docs both keys MEMBER_ROLES_ADD and MEMBER_ROLES_REMOVE are supposed to give us List<String> with role IDs. However we actually get List<Map<String, String>>, where the key is role's name and the value is it's ID.

Code Example for Reproduction Steps

AuditLogChange rolesAdded = auditLogEntry.getChangeByKey(MEMBER_ROLES_ADD);
Set<Long> addedRolesIds = extractRoleIds(rolesAddedChange);
    
private Set<Long> extractRoleIds(AuditLogChange change) {
        if (change == null || !(change.getNewValue() instanceof List<?> newValue)) {
            return Collections.emptySet();
        }

        return newValue.stream()
                .filter(Map.class::isInstance) // Works just fine
                .map(Map.class::cast)
                .map(map -> map.get("id"))
                .filter(Objects::nonNull)
                .map(String.class::cast)
                .map(Long::parseLong)
                .collect(Collectors.toUnmodifiableSet());
    }

Code for JDABuilder or DefaultShardManagerBuilder used

default

Exception or Error


AveCard1nal avatar Apr 08 '25 12:04 AveCard1nal