Ranking Bot Error || "!rbxinfo" Command does not work

Hello, I am currently working on my bot and I am having a problem with this command for the bot.
"!!rbxinfo"

Here is the problem code for it

if(isCommand('rbxinfo', message)){
    var username = args[1]
    if(username){
        message.channel.send("Roblox Serching........\n" + username)
        noblox.getIdFromUsername(username)
        .then(function(id){
            const emdims = new discord.MessageEmbed()
            .setTitle("Roblox Info on: " + id)
            .setDescription("Username: " + noblox.getUsernameFromId(id) + "\nUserId: " + id + "\nFriends: " + noblox.getFriends(id) + "\nFollowers: " + noblox.getFollowers(id) + "\nFollowing: " + noblox.getFollowings(id))
            message.channel.send(emdims)
            .then(function(){
                console.log("Serched")
            }).catch(function(err){
                message.channel.send("Critcal Error Logged to the console\n" + err)
                console.log(err)
            });
           }).catch(function(err){
               message.channel.send("" + err) 
           })
    }
}

Here is a tape of this error

So is there a way to fix this?
Since it will say this: [object Promise]
I am using Noblox.Js For this you can see.

Yeah, those methods all return a promise. You probably want to read up on Javascript Promises. Relevant bit:

Here’s how you use that promise:

promise.then(function(result) {
 console.log(result); // "Stuff worked!"
}, function(err) {
 console.log(err); // Error: "It broke"
});

then() takes two arguments, a callback for a success case, and another for the failure case. Both are optional, so you can add a callback for the success or failure case only.

2 Likes

Noblox returns promises, like posatta said.

Getting the username would look like (as well as a few other pieces of info):

const no = require("noblox.js");
no.getUsernameFromId(1).then(function(e){
  return e;
}).then(function(body){
  console.log(body); // ROBLOX
});

So you’ll need to make the requests then store them as variables THEN make the embeds.

Read the noblox.js docs.

In this case (or really in any case I guess) you don’t need both .then()s like I did by the way,

const no = require("noblox.js");
no.getUsernameFromId(1).then(function(e){
  console.log(e);
});

will work just fine too.

2 Likes