#Discord JDA Api make custom Requestcall for missing API feature. only gets null :(

25 messages · Page 1 of 1 (latest)

gray zinc
#
    private String avatar_decoration_asset_id(User u){
            new RestActionImpl<>(u.getJDA(), Route.Users.GET_USER.compile(u.getId()), (response, request) -> {
                DataObject json = response.getObject();
                String id =json.getObject("avatar_decoration_data").getString("asset");
                return id;
            });
        return null;
    }

https://discord.com/developers/docs/resources/user#avatar-decoration-data-object

{
  "avatar_decoration_data": {
    "sku_id": "1144058844004233369",
    "asset": "a_fed43ab12698df65902ba06727e20c0e"
  }
}

any idea what i made wrong? or other suggestion how to make a custom API call

knotty citrusBOT
#

This post has been reserved for your question.

Hey @gray zinc! Please use /close or the Close Post button above when your problem is solved. Please remember to follow the help guidelines. This post will be automatically closed after 300 minutes of inactivity.

TIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here.

feral pond
#

Well you have a return null; so that will always return null

#

What does json.getObject("avatar_decoration_data") return?

gray zinc
#

but it should return the id, and null only if the thing fails

#

dunno, i cant debug into that lambda

feral pond
#

You just always execute the return null;

#

Should the method be blocking?

gray zinc
#

no, i just want the string

#

but appearently the RestActionImplementaiton needs return

feral pond
#

Well you cannot get the string without blocking

#

but with blocking, you cannot get listeners

#

though you can return the RestAction and use .queue()

gray zinc
#

like i doing this for the first time, trying to reinvent a custom methode for an api thats not updated for everything yet. i debuged the User object appearently that doesnt contain all the raw data from the Discord API, only the fields the JDA api defined

#

with queue i get an void again, so i cannot return the string

#

lemme try this i guess

#

Caused by: net.dv8tion.jda.api.exceptions.ErrorResponseException: -1: net.dv8tion.jda.api.exceptions.ParsingException

#

yeah something is not working

#

the whole json is null

#

yeah i get the error always but i get parts of the jsons on some members. might be caching problem. i will need to change the iteration for something else for now and retest

gray zinc
#

thx got it to work

#
    private String avatar_decoration_asset_id(User u){

           RestActionImpl<String> restAction = new RestActionImpl<>(u.getJDA(), Route.Users.GET_USER.compile(u.getId()), (response, request) -> {

               DataObject json = response.getObject();
               if (json.isNull("avatar_decoration_data")){ return "none";}
               String id = json.getObject("avatar_decoration_data").getString("asset");
               return id;
           });

        try {
            return restAction.complete(true);
        } catch (RateLimitedException e) {
            System.out.println(e);
            return "none";
        }

    }