discord-multiclient
v1.0.0
Published
Run multiple independent Discord.js clients in the same process — each token is fully isolated.
Downloads
132
Maintainers
Readme
discord-multiclient
Run multiple independent Discord.js clients in the same process.
Each token is fully isolated — if one crashes or disconnects, the others keep running.
GitHub: ProjectInkDp/discord-multiclient
Install
npm install discord-multiclient discord.js
discord.jsv14 is required as a peer dependency.
Usage
const { MultiClient } = require("discord-multiclient");
const { GatewayIntentBits } = require("discord.js");
const manager = new MultiClient();
const intents = [GatewayIntentBits.Guilds, GatewayIntentBits.GuildMessages];
manager.add("bot-1", "TOKEN_1", { intents });
manager.add("bot-2", "TOKEN_2", { intents });
manager.add("bot-3", "TOKEN_3", { intents });
manager.on("ready", (id, client) => {
console.log(`[${id}] Logged in as ${client.user.tag}`);
});
manager.on("error", (id, err) => {
// Does NOT affect other clients
console.error(`[${id}] Error:`, err.message);
});
await manager.startAll();API
new MultiClient()
Creates a new manager.
.add(id, token, options)
Registers a new client. Does not start it yet.
| Param | Type | Description |
|---|---|---|
| id | string | Unique identifier for this client |
| token | string | Discord bot token |
| options | ClientOptions | Discord.js ClientOptions |
Returns: ClientEntry
.start(id)
Starts a single client by id.
.startAll()
Starts all registered clients concurrently.
Errors from individual clients are emitted — they do not reject this promise.
.destroy(id)
Destroys a single client and removes it from the manager.
.destroyAll()
Destroys all clients.
.getClient(id)
Returns the raw discord.js Client instance for the given id.
.getEntry(id)
Returns the ClientEntry for the given id.
.list()
Returns a summary of all clients:
[
{ id: "bot-1", status: "ready", tag: "MyBot#0001" },
{ id: "bot-2", status: "error", tag: null },
]Events
All events are emitted on the MultiClient instance, tagged with the client id.
| Event | Args | Description |
|---|---|---|
| ready | (id, client) | Client logged in successfully |
| error | (id, err) | Client encountered an error |
| disconnect | (id) | Client disconnected |
| shardError | (id, err) | WebSocket shard error |
| destroyed | (id) | Client was destroyed |
You can also listen to per-client events directly via getEntry(id).
Per-client listeners
const entry = manager.getEntry("bot-1");
entry.on("ready", (client) => {
client.on("messageCreate", (msg) => {
if (msg.content === "ping") msg.reply("pong");
});
});Status values
| Status | Meaning |
|---|---|
| idle | Not started yet |
| connecting | Login in progress |
| ready | Online and ready |
| error | Encountered an error |
| destroyed | Permanently stopped |
License
MIT © ProjectInkDp — maintained by doyimmiink
