Skip to main content

Server class

Properties

serverKey string

serverKey

The server's API key

authorizationKey string

authorizationKey

The production API key (null if not provided)

name string

name

The name of the Server (null if uninitiated)

ownerID string

ownerID

The user ID of the private server owner (null if uninitiated)

coOwnerIDs string[]

coOwnerIDs

An array of the user ID(s) of the server's co-owner(s) (null if uninitiated)

joinCode string

joinCode

The join code of the Server

verificationType AccountVerificationType

verificationType

The level of verification required to join the server (null if uninitiated)

teamBalanceEnabled boolean

teamBalanceEnabled

If team balance is enabled (null if uninitiated)

cache ResponseCache

cache

An object containing the last responses from a method. Should only be used if ratelimited and for rough estimates of the actual values.

Methods

constructor(key : string, authorizationKey? : string) returns Server

constructor

Creates a Server object with the provided server key and optional authorization key.

Example:

const { Server } = require("erlc.js");

const privateServer = new Server("SERVER-KEY", "AUTHORIZATION-KEY")
initiate() returns Promise<void>

initiate

Initiates the server. Fills out information and verifies server exists.

tip

You can call .initiate() multiple times on a single Server, it'll just update the information.

Example:

const { Server } = require("erlc.js");

const privateServer = new Server("SERVER-KEY", "AUTHORIZATION-KEY")
privateServer.initiate().then(() => {
console.log(`Initiated Server as ${privateServer.name}`)
})
makeRequest(endpoint: string, method?: string, version?: int, data?: object) returns Promise<Response>

makeRequest

Make a request to the ER:LC API to the provided endpoint. Providing data with the method being "GET" or "HEAD" will throw an error.

You will most likely not need to use this, as currently there are Server methods for every API endpoint.

Example:

const { Server } = require("erlc.js");

const privateServer = new Server("SERVER-KEY", "AUTHORIZATION-KEY")
privateServer.initiate()

privateServer.makeRequest(
"/server/command",
"POST",
1,
{
command: ":m Hello World!"
})
sendCommand(command: string, args?: string[]) returns Promise<Response>

sendCommand

Sends the provided command to the Server, along with the provided arguments.

Example:

const { Server } = require("erlc.js");

const privateServer = new Server("SERVER-KEY", "AUTHORIZATION-KEY")
privateServer.initiate()

privateServer.sendCommand("m", ["Hello World!"])
getPlayers() returns Promise<Player[]>

getPlayers

Gets the list of currently online Players in the Server.

Example:

const { Server } = require("erlc.js");

const privateServer = new Server("SERVER-KEY", "AUTHORIZATION-KEY")
privateServer.initiate()

privateServer.getPlayers().then(players => {
const randomPlayer = players[Math.floor(Math.random() * players.length)]
console.log(`${randomPlayer.username} won the player bingo!`)
})
getSpawnedVehicles() returns Promise<Vehicle[]>

getSpawnedVehicles

Gets the list of currently spawned Vehicles in the Server.

Example:

const { Server } = require("erlc.js");

const privateServer = new Server("SERVER-KEY", "AUTHORIZATION-KEY")
privateServer.initiate()

privateServer.getSpawnedVehicles().then(vehicles => {
for(let i = 0; i > vehicles.length; i++){
console.log(`${vehicles[i].ownerUsername} has a ${vehicles[i].name} spawned!`)
}
})
getModeratorCalls() returns Promise<ModeratorCall[]>

getModeratorCalls

Gets the list of ModeratorCalls in the Server.

Example:

const { Server } = require("erlc.js");

const privateServer = new Server("SERVER-KEY", "AUTHORIZATION-KEY")
privateServer.initiate()

privateServer.getModeratorCalls().then(calls => {
for(let i = 0; i > calls.length; i++){
console.log(`${calls[i].playerUsername}'s moderator call was made at ${vehicles[i].date.getHours()}:${vehicles[i].date.getMinutes()}.`)
}
})
getJoinLogs() returns Promise<JoinLog[]>

getJoinLogs

Gets the list of JoinLogs from the Server.

Example:

const { Server } = require("erlc.js");

const privateServer = new Server("SERVER-KEY", "AUTHORIZATION-KEY")
privateServer.initiate()

privateServer.getJoinLogs().then(joinLogs => {
const randomJoinLog = joinLogs[Math.floor(Math.random() * players.length)]
console.log(`${randomJoinLog.username} won the bingo!`)
})
getModerationLogs() returns Promise<ModerationLog[]>

getModerationLogs

Gets the list of ModerationLogs from the Server.

Example:

const { Server } = require("erlc.js");

const privateServer = new Server("SERVER-KEY", "AUTHORIZATION-KEY")
privateServer.initiate()

privateServer.getModerationLogs().then(modLogs => {
console.log(`The most recent mod log was by ${modLogs[0].moderatorUsername}`)
})
getCustomLogs() returns Promise<ModerationLog[]>

getCustomLogs

Gets the list of ModerationLogs where the command equals "log" from the Server.

Example:

const { Server } = require("erlc.js");

const privateServer = new Server("SERVER-KEY", "AUTHORIZATION-KEY")
privateServer.initiate()

privateServer.getCustomLogs().then(customLogs => {
console.log(`The most recent custom log was by ${customLogs[0].moderatorUsername}`)
})
getKillLogs() returns Promise<KillLog[]>

getKillLogs

Gets the list of KillLogs from the Server.

Example:

const { Server } = require("erlc.js");

const privateServer = new Server("SERVER-KEY", "AUTHORIZATION-KEY")
privateServer.initiate()

privateServer.getKillLogs().then(killLogs => {
for(let i = 0; i > killLogs.length; i++){
console.log(`${killLogs.killerUsername} killed ${killLogs.killedUsername}!`)
}
})