Star ✨ on GitHub

Configuration

Token, nodes, debug logs, and node rotation behavior (all config-driven).

A bot that you can maintain is a bot where secrets and tuning knobs live in config, not scattered through code.

This page covers:

  • where to store your token safely
  • how to configure multiple nodes (main + backup)
  • how to toggle Moonlink debug logs from config
  • how node selection and player failover work

config.json (classic approach)

Create a config.json in your project root:

{
  "token": "YOUR_TOKEN_HERE",
  "prefix": "!",

  "debug": true,

  "lavalink": {
    "nodes": [
      {
        "identifier": "main",
        "host": "127.0.0.1",
        "port": 2333,
        "password": "youshallnotpass",
        "secure": false,
        "priority": 1
      },
      {
        "identifier": "backup",
        "host": "127.0.0.1",
        "port": 2444,
        "password": "youshallnotpass",
        "secure": false,
        "priority": 0
      }
    ]
  },

  "moonlink": {
    "options": {
      "clientName": "MyMoonlinkBot/1.0.0",

      "node": {
        "selectionStrategy": "leastLoad",
        "avoidUnhealthyNodes": true,
        "maxCpuLoad": 80,
        "maxMemoryUsage": 0.9,
        "autoMovePlayers": true,
        "retryAmount": 10,
        "retryDelay": 5000
      },

      "defaultPlayer": {
        "autoPlay": true,
        "selfDeaf": true
      }
    }
  }
}

Debug logs (controlled by config)

Moonlink emits a debug event with helpful internal messages.

A solid rule:

  • debug: true → attach the listener and print logs
  • debug: false → do nothing (clean production output)

You’ll see the exact wiring inside the Creating Your First Bot page.

Most bots don’t rotate nodes manually.

What usually happens is:

  1. You configure multiple nodes.
  2. When a player is created, Moonlink chooses a node based on your selection strategy.
  3. If a node disconnects and autoMovePlayers is enabled, Moonlink can move players to another healthy node.

selectionStrategy

moonlink.options.node.selectionStrategy controls how Moonlink picks the best node:

  • leastLoad (default): balances using penalties/load.
  • players: fewest total players.
  • playingPlayers: fewest active players.
  • memory: most free memory.
  • cpuSystem: lowest system CPU load.
  • uptime: highest uptime.
  • random: random node.
  • priority: uses each node’s priority.

autoMovePlayers (failover)

When autoMovePlayers: true, a node going offline can trigger player migration.

Environment variables (.env)

If you prefer secrets outside JSON, use env vars:

DISCORD_TOKEN=...
LAVALINK_HOST=127.0.0.1
LAVALINK_PORT=2333
LAVALINK_PASSWORD=youshallnotpass