2
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

# 【非公式API】Xserver for Game をブラウザなしで操作できる `xserver-client` を作った

2
Last updated at Posted at 2026-04-12

Xserver for Game をブラウザなしで操作したいと思ったことありませんか?

  • 毎回ログインして延長押すのが面倒
  • コマンド送信や再起動を自動化したい
  • ファイルを外部から操作したい
  • Discord Botと連携したい

そんな用途向けに、Node.js向けの非公式APIラッパーを作りました。


🔧 xserver-client とは

xserver-client は、Xserver for Game を外部から操作できる Node.js 用の非公式APIラッパーです。

内部で Playwright を使用してログイン処理を自動化し、ブラウザを開かずに様々な操作を実行できます。

現在対応している主な機能:

  • ログイン
  • 無料枠48時間延長
  • コンソールコマンド送信
  • サーバー起動 / 停止 / 再起動
  • ログ取得
  • ファイル読み込み / 書き込み
  • アップロード / ダウンロード
  • リネーム
  • 解凍
  • 削除
  • ファイル一覧取得

Java版 / Bedrock版 の両方に対応しています。


📦 インストール

npm install xserver-client

Playwright も必要です。

npm install playwright
npx playwright install

🚀 基本的な使い方

const { XServerClient } = require('xserver-client');

async function run() {
  // Java版 → "je"
  // Bedrock版 → "be"
  const xserver = new XServerClient("サーバーID", "je", true);

  // ログイン
  const loggedIn = await xserver.login(
    "メールアドレス",
    "パスワード"
  );

  if (!loggedIn) {
    console.log("Login failed");
    return;
  }

  // 残り期限取得
  const status = await xserver.getLimitStatus();
  console.log(status);

  // 操作用トークン取得
  await xserver.fetchLoginToken();

  // 48時間延長
  await xserver.refresh(48);

  // コマンド送信
  await xserver.sendCommand("say Hello World");

  // 再起動
  await xserver.restart();
}

run();

⚡ サーバー操作

// 起動
await xserver.start();

// 停止
await xserver.stop();

// 再起動
await xserver.restart();

// コマンド送信
await xserver.sendCommand("say Server Restarting");

📜 ログ取得

リアルタイム監視っぽく使うこともできます。

setInterval(async () => {
  const log = await xserver.getLog();

  if (log) {
    console.log(log);
  }
}, 2000);

Discord Bot連携にも便利です。


📂 ファイル操作

ファイルマネージャーもAPI化しています。

const targetDir = "/minecraft/worlds/Bedrock level";

// ファイル読み込み
const content = await xserver.getFileContent(
  `${targetDir}/levelname.txt`
);

console.log(content);

// ファイル保存
await xserver.saveFileContent(
  `${targetDir}/note.txt`,
  "Hello World"
);

// アップロード
await xserver.uploadFile(
  targetDir,
  Buffer.from("test data"),
  "test.txt"
);

// ダウンロード
const file = await xserver.downloadResource(
  `${targetDir}/test.txt`
);

// リネーム
await xserver.renameFile(
  `${targetDir}/test.txt`,
  "renamed.txt"
);

// zip解凍
await xserver.decompressFile(
  `${targetDir}/backup.zip`
);

// 削除
await xserver.deleteFile(
  `${targetDir}/old.txt`
);

📁 ファイル一覧取得

以前の xserver-mgrScanner は統合され、現在は xserver-client の中に含まれています。

const {
  XServerClient,
  XserverMgrScanner
} = require('xserver-client');

(async () => {
  const xserver = new XServerClient(
    "サーバーID",
    "be",
    true
  );

  await xserver.login(
    "メールアドレス",
    "パスワード"
  );

  await xserver.fetchLoginToken();

  const scanner = new XserverMgrScanner(xserver);

  const files = await scanner.getFiles(
    "/minecraft/worlds",
    {
      suffix: "manifest.json"
    }
  );

  console.log(files);
})();

📦 戻り値例

[
  {
    name: "world1",
    type: "folder",
    fullPath: "/minecraft/worlds/world1/manifest.json",
    size: 12345,
    lastModified: "2026-01-01"
  }
]

🔐 ログインについて

ログインには Playwright を使用しています。

初回はブラウザ起動の関係で少し時間がかかります。

また、以下をOFFにしておく必要があります。

ログインセキュリティ設定から「不審なログイン時の認証」を無効にしてください(有効だとログインに失敗します)


⚠️ 注意点

これは非公式APIです。

Xserver側の仕様変更によって突然動かなくなる可能性があります。

また、内部的にはWeb画面を自動操作しているため、完全な安定性は保証できません。


💡 使い道

  • 48時間延長の完全自動化
  • Discord Botとの連携
  • サーバー監視
  • 自動バックアップ
  • Webパネル自作
  • ファイル操作ツール
  • ログ監視Bot

など。


🔚 まとめ

毎回ブラウザを開いてポチポチする作業を、全部コードに任せられるようになります。

特に無料枠ユーザーにはかなり便利です。

もしよかったらスターください 🙏
PR・改善提案も歓迎です。

2
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?