Getting the server logs
tip
This page only covers a few log methods, for more of them, go to the full documentation for the Server class.
Getting the moderation logs
To get the moderation logs, there's already a built-in .getModerationLogs()
method.
main.js
privateServer.getModerationLogs().then(logs => { // Request the moderation logs and wait for them to come back
console.log(`The most recent command was ':${logs[0].command}', and it was sent by ${logs[0].moderatorUsername}.`)
})
Here's an example response from .getModerationLogs()
Example Response from .getModerationLogs()
[
{
command: "kick",
moderatorUsername: "david.baszucki",
moderatorUserID: "987654321",
date: "2006-09-01T12:00:00.000Z"
}
]
Getting the join logs
There's also a built-in .getPlayers()
method, which gives you all of the players as Player
objects.
Example response from .getPlayers()
{
Player,
Player,
Player
}
Now, you might notice that we've just put Player
in the player list, but don't worry, you won't just get the word 'Player' when you use this method! We've just shortened the response because the Player
object has quite a few different properties.
Here's how you can use this player list to make a player bingo:
main.js
privateServer.getPlayers().then(players => { // Request the player list and wait for it to come back
const randomPlayer = players[Math.floor(Math.random() * players.length)] // Get a random online player (its a bit more complicated to get a random number is JS!)
console.log(`The lucky online player is: ${randomPlayer.username}! Congratulations!`) // Congratulate the winner!
})