npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

discord-bots-manager

v4.2.0

Published

Spawn and manage multiple Discord bot processes from a single manager using child_process.fork()

Readme

discord-bots-manager

Spawn, monitor, and manage multiple Discord bot processes from a single Node.js process.

Each bot runs in its own isolated child process (child_process.fork), so a crash in one bot never affects the others. The manager handles auto-restarts, IPC communication, and graceful shutdown.

Features

  • Discord Bot Management — manage multiple Discord bots from a single manager process
  • Multi-Process Isolation — each bot runs in its own OS process via child_process.fork
  • Auto-Restart — automatic restart on crash with configurable delay and max retry count
  • IPC Communication — send and receive messages between the manager and any bot process
  • Cluster & Sharding Ready — built for sharded and clustered Discord bot architectures
  • Process Lifecycle Control — start, stop, and restart individual bots or all at once
  • Graceful Shutdown — sends shutdown signal, then SIGKILL after configurable timeout
  • Status Monitoring — query real-time PID, status, uptime, and restart count per bot
  • Event System — rich lifecycle events: start, ready, crash, restart, stop, error
  • TypeScript First — full type declarations included out of the box

Install

npm install discord-bots-manager

Peer dependency: requires discord.js@^14

Quick Start

Manager (index.js)

import { Manager } from 'discord-bots-manager'

const manager = new Manager({
  bots: [
    {
      name: 'mod-bot',
      token: process.env.MOD_BOT_TOKEN!,
      script: './bot.js',
    },
    {
      name: 'music-bot',
      token: process.env.MUSIC_BOT_TOKEN!,
      script: './bot.js',
      restartDelay: 5000,
      maxRestarts: 3,
    },
  ],
})

manager.on('bot:ready', (name) => console.log(`${name} is online`))
manager.on('bot:crash', ({ name, code }) =>
  console.error(`${name} crashed (exit ${code})`))

manager.startAll()

process.on('SIGINT', () => {
  manager.stopAll()
  process.exit(0)
})

Bot worker (bot.js)

This is the script the manager forks. It receives BOT_NAME, BOT_TOKEN, and BOT_INTENTS via environment variables.

import { Client, GatewayIntentBits } from 'discord.js'
import type { IPCMessage } from 'discord-bots-manager'

const client = new Client({
  intents: Number(process.env.BOT_INTENTS) || GatewayIntentBits.Guilds,
})

client.once('ready', () => {
  // Notify the manager that the bot is online
  process.send?.({ type: 'ready', from: 'worker', botName: process.env.BOT_NAME, timestamp: Date.now() })
})

// Listen for messages from the manager
process.on('message', (msg: IPCMessage) => {
  if (msg.type === 'shutdown') {
    client.destroy()
    process.exit(0)
  }
})

client.login(process.env.BOT_TOKEN)

API

Manager

| Method | Description | |---|---| | startAll() | Start all registered bots | | start(name) | Start a specific bot | | stopAll() | Stop all bots gracefully | | stop(name) | Stop a specific bot | | restartAll() | Restart all bots | | restart(name) | Restart a specific bot | | addBot(config) | Register a new bot at runtime | | removeBot(name) | Stop and remove a bot | | sendTo(name, type, payload?) | Send IPC message to a specific bot | | broadcast(type, payload?) | Send IPC message to all bots | | status() | Get status array for all bots | | statusOf(name) | Get status of one bot |

Events

| Event | Payload | |---|---| | bot:start | string (name) | | bot:ready | string (name) | | bot:crash | { name, code, signal } | | bot:restart | string (name) | | bot:stop | string (name) | | bot:error | { name, error } | | bot:message | (msg: IPCMessage, name: string) |

BotConfig

| Field | Type | Default | Description | |---|---|---|---| | name | string | — | Unique identifier for the bot | | token | string | — | Discord bot token (injected as BOT_TOKEN env) | | script | string | — | Path to the worker script | | intents | number | 0 | Discord.js intents bitfield | | env | Record<string, string> | {} | Extra env variables | | restartDelay | number | 2000 | Delay before restart (ms) | | maxRestarts | number | Infinity | Max auto-restart attempts |

Examples

Clone the repo and run:

npm install
npm run build
node examples/manager.js

See the examples directory for a complete manager + worker setup.

Contributing

See CONTRIBUTING.md.

License

MIT