MyMCLib Library Documentation

A JavaScript library for interacting with the My-MC.Link API

Home

Overview

The MyMCLib library provides a convenient way to interact with the My-MC.Link API for managing Minecraft servers. It includes methods for performing various actions such as retrieving server information, managing server settings, controlling gameplay, and interacting with players.

Installation

To use the MyMCLib library in your project, install it via npm:

npm install mymc-lib

Proper Importing: To make use of this module, you'll need to either utilize the .mjs extension or incorporate "type": "module" in your package.json file. This ensures compatibility with ECMAScript modules.

Usage

First, import the library and create an instance with your API token:

import MyMCLib from "mymc-lib";

const MyMC = new MyMCLib("your-api-token");

Example Usage: Retrieve information about your API key's expiration date.

import MyMCLib from "mymc-lib";

// Instantiate MyMCLib with your API token
const MyMC = new MyMCLib("your-api-token");

// Will print information about API key expiration date
let keyData = await MyMC.getTime();

console.log(keyData);

Output:

{
  success: true,
  keyexpireString: 'Tue Apr 15 2025 06:14:59 GMT-0400 (Eastern Daylight Time)',
  expireDate: '2025-04-15T10:14:59.000Z',
  expireEpoch: 1744712099000
}

Code Examples

Getting Server Time

const timeData = await MyMC.getTime();
console.log(timeData);

Getting Server Statistics

const statsData = await MyMC.getStats();
console.log(statsData);

Getting Server Logs

const logData = await MyMC.getLog();
console.log(logData);

Starting the Minecraft Server

const startResult = await MyMC.startServer();
console.log(startResult);

Stopping the Minecraft Server

const stopResult = await MyMC.stopServer();
console.log(stopResult);

Restarting the Minecraft Server

const restartResult = await MyMC.restartServer();
console.log(restartResult);

Getting Connection Hash

const hashData = await MyMC.getConnectionHash();
console.log(hashData);

Getting SFTP Connection Hash

const sftpHashData = await MyMC.getConnectionHashSFTP();
console.log(sftpHashData);

Getting Online Players

const playersData = await MyMC.getOnlinePlayers();
console.log(playersData);

Getting Server's Website URL

const websiteURL = await MyMC.getWebsiteURL();
console.log(websiteURL);

Getting Server's Map URL

const mapURL = await MyMC.getMapURL();
console.log(mapURL);

Banning a Player

const banResult = await MyMC.postBan("username");
console.log(banResult);

Unbanning a Player

const unbanResult = await MyMC.postUnban("username");
console.log(unbanResult);

Sending a Message to All Players

const sayResult = await MyMC.postSay("Hello, everyone!");
console.log(sayResult);

Sending a Private Message to a Player

const tellResult = await MyMC.postTell("username", "Hey, how are you?");
console.log(tellResult);

Executing a Command in Server Console

const consoleResult = await MyMC.postConsole("say Hello, world!");
console.log(consoleResult);

Giving an Item to a Player

const giveResult = await MyMC.postGive("username", "item", 1);
console.log(giveResult);

Installing a Mod by ID

const modID = "exampleMod123";
const installResult = await MyMC.installMod(modID);
console.log(installResult);

Uninstalling a Mod by ID

const modID = "exampleMod123";
const uninstallResult = await MyMC.uninstallMod(modID);
console.log(uninstallResult);

Retrieving a List of Installed Mods

const installedMods = await MyMC.getInstalledMods();
console.log(installedMods);

API Reference

MyMCLib Class

Constructor

constructor(token: string)

Creates an instance of the MyMCLib class with the provided API token.

Methods

ApiUtils Class

Methods

Java Client

We also have a Java client that provides the same functionality. View the documentation at:

Java Client Documentation

Explore More

Ready to automate your server with MyMCLib
Join our community, dive into our resources, and start building with the My-MC.Link API.