Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/noskap/kojima-bot/llms.txt

Use this file to discover all available pages before exploring further.

Kojima Bot is a Bun-native application and ships with two supported ways to keep it running: launching it directly with bun start, or using PM2 with the included ecosystem.config.cjs for process supervision, automatic restarts, and log management. Choose whichever fits your infrastructure — both approaches are covered below.

Development mode

During active development, use bun run dev. This invokes bun run --watch src/index.ts, which monitors source files for changes and restarts the process automatically whenever you save.
bun run dev
The --watch flag is convenient for iterating on commands or logic, but it should not be used in production — an accidental file write or an in-progress edit could cause unexpected restarts while users are interacting with the bot.

Production: direct Bun

The simplest production deployment is to run the bot entry point directly with Bun:
bun start
This executes bun run src/index.ts with no process manager involved. It is straightforward and works well if you manage the process lifecycle yourself (e.g. via a systemd unit, a container restart policy, or a shell nohup).

Production: PM2

PM2 is a process manager that keeps the bot alive across crashes, restarts it on reboot, and provides a built-in logging subsystem. The repository includes a ready-to-use ecosystem.config.cjs.
1

Install PM2

Install PM2 globally using Bun:
bun add -g pm2
2

Review the ecosystem config

The included ecosystem.config.cjs configures PM2 to run the bot using Bun as the interpreter and ensures Bun’s binary directory is on the PATH:
module.exports = {
    apps: [
        {
            name: "kojima-bot",
            script: "src/index.ts",
            interpreter: "bun",
            env: {
                PATH: `${process.env.PATH}:${process.env.HOME}/.bun/bin`,
            },
        },
    ],
};
3

Start the bot

Launch the bot under PM2:
pm2 start ecosystem.config.cjs
4

Monitor logs

Stream live output from the bot process:
pm2 logs kojima-bot
5

Save and enable autostart

Persist the PM2 process list and generate a startup hook so the bot resumes after a server reboot:
pm2 save && pm2 startup
Follow the instructions that pm2 startup prints — it will output a command to run as root that installs the init-system hook for your OS.

Registering slash commands

Before users can interact with the bot’s slash commands, you must register them with Discord. Run the deploy script once after installation, and again whenever you add, rename, or remove commands:
bun run deploy
This executes src/deploy-commands.ts, which registers all commands as guild-scoped commands against the server identified by GUILD_ID in your .env. Guild-scoped commands appear instantly (unlike global commands, which can take up to an hour to propagate).

Environment file

The bot reads configuration at startup from a .env file in the working directory. Make sure .env is present and populated before starting the process:
# Copy the example and fill in your values
cp .env.example .env
The three required variables are DISCORD_TOKEN, CLIENT_ID, and GUILD_ID. All other variables are optional. See the Configuration page for the full reference.
PM2 uses Bun as the interpreter (interpreter: 'bun') — make sure Bun is on the system PATH or specify the full path in ecosystem.config.cjs. The ecosystem config already appends $HOME/.bun/bin to PATH for convenience, but if Bun is installed elsewhere you may need to adjust that value.
Set HOME to a writable directory if running in restricted environments: HOME=/var/mybot bun start

Build docs developers (and LLMs) love