[NOBLOX-JS] "Error: setRank: Rank number must be a number" when it is a number?

Error: setRank: Rank number must be a number

That is the error I am getting from my JavaScript ranking bot. I am using the req.query function to get the URL parameters.

snip

I am getting the error from line 20 in that snip. The logs tell me all the parameters have been received, but I am still getting an error for the setRank function.

The ‘item’ parameter is a number, and im setting the user-id’s rank with the roleset number.

sni2

snip3

As you can see, the item variable (which is also a parameter in the bot get function) is a number. I am not sure what to do as I am stuck. Please help me!

let item = req.query.item;
console.log(typeof item, item);

Run this and see what the type of item really is. If it’s a string, parse it:

let item = parseInt(req.query.item) || 0;

if(item == 0) console.log("Couldn't parse int:", req.query.item);

Now I’m getting an error saying the role does not exist.

Did you output the typeof req.query.item as demonstrated? If it’s a string, is there any whitespace i.e " 100"?

let item = parseInt(req.query.item) || 0;
console.log("req.query.item:", typeof req.query.item, req.query.item);
console.log("item:", typeof item, item);

Try running this sample code, it will output the type of req.query.item and what it contains (should say “string 100” or “number 100”)

It also outputs the type after it was converted to an integer by parseInt()

Let me know what this outputs.

The reason I ask is because it looks to me like your web application in NodeJS is converting the “100” role into a string during the JSON conversion.

Outputting the types and raw values of both req.query.item and the parseInt variant will give you insight on whether or not this is a type issue.

snip41

Alright so yeah, req.query.item was a string not a number. parseInt did correctly turn it into a number, so this means that the issue is either:
A) No role exists in the group with the ID of 2
B) There’s an internal noblox issue that is causing this not to work

Please verify that a role exists in your group with the ID of 2.

Edit: looks like noblox is complaining that the role doesn’t exist actually:

Yeah, so I changed a couple of things and now I am getting a new error. I believe the order of the parameters in the setRank function is wrong. Also, should I parse the userID or should it be left as a string?

I also tried changing the rank id from 100 to 2 as it is the second rank from the lowest one.

I would parse it even if it’s not complaining about it, just because their documentation says it should be a number.

image

Judging by their docs, it looks like you have two options.
If you have a rank “Example” with an ID of 2 you can use the API in either way:
.setRank(Group, User, 2) or .setRank(Group, User, “Example”)

Try using the name instead of the RoleID and see if that changes the result.

What’s the error your getting?

Also - fyi, this function returns a promise that you are not acknowledging.

rbx.setRank(group, id, item).then((result) => {
// it worked, result will be the role we gave, lets output it:
console.log(result)
}).catch((err) => {
// it failed, lets output the error:
console.error(err);
});
1 Like

When changing the rank id to 2, the error goes away but I problem comes up with the userid (which still happened when parsing and when left as a string).

Unhandled rejection Error: 400 The user is invalid or does not exist.

That looks to be saying the user does not exist - are you parsing the userid as an int? It looks like it doesn’t like the userid being a string.

Yep, I am.

dasd23a

EDIT:

I got the parameter order correct too.

dasd2

Alright, let’s try outputting that and seeing if it looks normal

console.log(typeof id, id);

Alright. I am now going to try that.

It is a number. I correctly parsed it.

Huh that’s odd, are you positive that user id is in your group? And are they ranked below your bot? Your bot can only manage people below its current rank.

1 Like

.

I just realised I put the wrong group id. Even if I still got most of the script correct, I am thanking you gratefully as you taught me a thing or two about parsing and checking through one’s script. Thank you for your time.

1 Like