Answer the question
In order to leave comments, you need to log in
How to fix [object Promise]?
There is a "minecraft-server-util" module, and there is a method for getting information about the server, I added the ability to get online servers to the function, and everything seemed to work fine, but when I try to output the result somewhere other than the console, [object Promise] is displayed ].
async function getCurrentOnline(address, port) {
try {
const response = await util.status(address, { port: port, enableSRV: true, timeout: 5000, protocolVersion: 47 });
return `${response.onlinePlayers}`;
} catch (error) {
throw error;
}
}
getCurrentOnline('mc.hypixel.net.', 25565).then(count => count) // [object Promise]
getCurrentOnline('mc.hypixel.net.', 25565).then(count => console.log(count)) // Нормальный вывод
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question