So I have this Discord Bot command that displays the user's servers from an API: The "GetAllServers" returns A JSON that for me has two objects in but this could go up or down. The "GetServerStatus" Returns Either "on", "off or "starting".
I want to be able to display a nicely formatted version of the "on", "off" or starting into a discord embed along with some other values retrieved from GetserverStatus.
To display the information in an embed I have written a loop to go through each individual server and retrieve the status for the server and retrieve the information and post it as a separate field in an embed.
Here is my code:
const servers = new Discord.MessageEmbed()
.setColor(2718207)
.setTitle(`${user.username}'s Servers`)
.setTimestamp()
.setFooter(
`Test`,
`https://test.com`
);
Client.getAllServers().then((response) => {
response.forEach(function (element) {
Client.getServerStatus(element.attributes.identifier).then(
(Server_Status) => {
console.log(Server_Status);
if (Server_Status === "off") {
servers.addField(
`__${element.attributes.name}__`,
`**Identifier:** ${element.attributes.identifier}\n**Server Status:** Offline\n**Players Online:** 0/30\n`,
true
);
} else if (Server_Status === "on") {
servers.addField(
`__${element.attributes.name}__`,
`**Identifier:** ${element.attributes.identifier}\n**Server Status:** Online\n**Players Online:** 0/30\n`,
true
);
} else if (Server_Status === "starting") {
servers.addField(
`__${element.attributes.name}__`,
`**Identifier:** ${element.attributes.identifier}\n**Server Status:** Starting\n**Players Online:** 0/30\n`,
true
);
Console.log("Starting");
}
}
);
});
message.channel.send(server);
});
the issue I am having is that the if statement isn't running although the correct values are returned of the GetServerStatus. I have tested many times by just console.log(Server_Status) and it always returns either "on" "off" or starting". However when trying them in an if statement it doesn't work.