-
Notifications
You must be signed in to change notification settings - Fork 7
Standalone Instance
Mika Bojovic edited this page Nov 2, 2025
·
4 revisions
This example shows how to launch Galactic in standalone mode, running multiple clusters and shards on a single machine for efficient scaling.
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.
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.tsto manage bot shards. - Extend the Discord client, passing cluster references for full access to sharding info.
Build and launch the bot as usual:
node dist/index.jsYour standalone instance will start multiple clusters and shards according to your configuration. On each restart, Galactic automatically balances the workload.
- Explore galactic bridge for distributed setups
If you have questions or want to contribute, visit GitHub discussions or the issue tracker.
