Upon starting the bot console, the console displays:
Online with undefined/5
After 10 seconds, an error is thrown:
undefined:1 [object Promise] ^ SyntaxError: Unexpected token o in JSON at position 1
This is the code snippet being used:
let players
client.on("ready", async () => {
async function fetchOnlinePlayers() {
const response = fetch(`http://ip:port/dynamic.json`);
const data = JSON.parse(response);
players = data.clients;
}
async function autoconnect() {
if (players === -1) {
console.log('Offline');
} else {
console.log('Online with ' + players + '/5');
}
}
autoconnect()
setInterval(() => {
client.user.setStatus('dnd');
client.user.setActivity(`Online with ${players} players.`, { type: 'PLAYING' })
fetchOnlinePlayers()
}, 10000)
})