Skip to content

Messaging

Moritz edited this page Nov 7, 2025 · 2 revisions

Galactic Logo

Getting Started: Messaging

A Messaging system allows communication between different clusters or instances in a Galactic setup. This is particularly useful for sending commands, data, or events across multiple shards or clusters, enabling coordinated behavior in a distributed bot architecture.


Overview

Bridge -> Cluster of Guild

The Bridge can send messages to specific clusters using the sendToCluster method. This allows the Bridge to communicate directly with any cluster it manages.

// Bridge
sendRequestToGuild(cluster: BridgeClientCluster, guildID: Snowflake, data: unknown, timeout = 5000): Promise<unknown>;
// Cluster

cluster.on('request', (message: unknown, resolve: (data: unknown) => void, reject: (error: any) => void) => {
     // resolve({ ... }); 
     // or
     // reject({ ... });
})

Instance -> Cluster of Guild

An Instance can send messages to its clusters using the sendRequestToClusterOfGuild method. This is useful for coordinating actions or sharing data between the instance and its clusters.

instance.sendRequestToClusterOfGuild(guildID: string, message: unknown, timeout?: number): Promise<unknown>

You can also send messages without needing an guildID.

sendRequestToCluster(cluster: ClusterProcess, message: unknown, timeout?: number): Promise<unknown>;

Cluster -> Another Cluster of Guild

If you need to send messages between clusters, you can do so by routing the message through the Bridge or Instance.

sendRequestToClusterOfGuild(guildID: string, message: unknown, timeout?: number): Promise<unknown>;
sendMessageToClusterOfGuild(guildID: string, message: unknown): void;

Broadcast Eval

Like discord.js's Client#broadcastEval, Galactic provides a way to evaluate code across all clusters or instances. This is useful for gathering information or executing commands in a distributed manner.

// Cluster
const guildCount = await client.cluster.broadcastEval((client) => {
    return client.guilds.cache.size;
}).then((results) => {
    return results;
}).catch((error) => {
    return [] as number[];
});

Clone this wiki locally