Skip to content

Standalone Instance

Mika Bojovic edited this page Nov 2, 2025 · 4 revisions

Galactic Logo

Getting Started: Standalone Instance

This example shows how to launch Galactic in standalone mode, running multiple clusters and shards on a single machine for efficient scaling.

Step 1: Setup Your Entrypoint

Create an index.ts file to launch the standalone instance.

import {StandaloneInstance} from "galactic.ts";

// Create a standalone instance running 2 clusters with 2 shards each
const machine = new StandaloneInstance(
    `${__dirname}/bot.js`,
    2, 2, process.env.TEST_SA_BOT_TOKEN!, 
    []
);

machine.start();
  • The first argument is the path to your bot entry script.
  • The second argument sets the number of clusters, and the third sets shards per cluster.
  • Pass your Discord bot token, and optionally extra arguments.

Step 2: Implement Your Bot Logic

In your bot.ts, initialize the bot and handle clustering integration.

import {Cluster} from "galactic.ts";
import {Client, ClientOptions} from "discord.js";

// Extend the Discord Client to include a reference to its Cluster
export class ExtendedClient extends Client {
    cluster: Cluster<ExtendedClient>;

    constructor(options: ClientOptions, cluster: Cluster<ExtendedClient>) {
        super(options);
        this.cluster = cluster;
    }
}

// Initialize the Cluster
const cluster = Cluster.initial<ExtendedClient>();

const client = new ExtendedClient({
    shards: cluster.shardList,
    shardCount: cluster.totalShards,
    intents: cluster.intents,
}, cluster);

cluster.client = client;

client.login(cluster.token)
  • Use the Cluster API from galactic.ts to manage bot shards.
  • Extend the Discord client, passing cluster references for full access to sharding info.

Step 3: Run Your Bot

Build and launch the bot as usual:

node dist/index.js

Your standalone instance will start multiple clusters and shards according to your configuration. On each restart, Galactic automatically balances the workload.


Next Steps


If you have questions or want to contribute, visit GitHub discussions or the issue tracker.

Clone this wiki locally