Skip to content

Starting the Bot

With your .env file in place (see Configuration), you are ready to start iHorizon.

Starting iHorizon

Run the following command from the root of the project directory (the bot reads .env from the folder it is started in):

bun .

The bot should now come online in your Discord server. If you run into any problems at this stage, check the Common Issues page.

Keeping the Bot Running with pm2

By default, the bot stops as soon as you close your terminal. To keep it running in the background, restart it when it crashes and start it with the machine, use pm2, a process manager. The installation script sets all of this up for you; the steps below do it by hand.

1. Install Node.js and pm2

pm2 runs on Node.js. On a Debian-based Linux distribution:

sudo apt install nodejs npm
sudo npm install -g pm2
pm2 -v

Alternative installation methods for Node.js are available on the official Node.js website. If pm2 -v prints a version number, pm2 is ready.

2. Start iHorizon with pm2

From the root of the project:

pm2 start pm2.config.cjs
pm2 save

pm2.config.cjs is both the pm2 configuration and the launcher pm2 runs. On every start and every automatic restart, it:

  1. stops the bot processes left over from a previous run of this folder, so two copies of the bot never answer at the same time;
  2. installs a Bun for the project in ./.bun (ignored by Git) the first time, and upgrades it on the next starts;
  3. runs git pull, then bun install --production, so a restart is also an update;
  4. starts the bot (src/index.ts).

A failed cleanup, upgrade, pull or install is logged, and the bot starts with what is already there.

Keep your changes out of the tracked files

Since every restart runs git pull, a local change to a tracked file can make the pull fail. Keep your settings in .env (ignored by Git), and your own code changes on a branch or a fork.

3. Start iHorizon with the machine

pm2 startup
# Run the command it prints, then:
pm2 save

Everyday commands

Command What it does
pm2 logs iHorizon Shows the bot's logs live
pm2 restart iHorizon Restarts the bot (and updates it with git pull)
pm2 stop iHorizon Stops the bot until the next pm2 start
pm2 list Lists the processes pm2 manages

Started iHorizon with pm2 start . before?

Older guides started the bot with pm2 start . --interpreter ~/.bun/bin/bun, which skips the cleanup and the updates above. Switch to the launcher once: pm2 delete iHorizon && pm2 start pm2.config.cjs && pm2 save.

Adding or removing commands, events or SVG templates

Shards don't scan the source folders: they load the files listed in src/exports/ (commands, subcommands, events, buttons, select menus, client.func functions and SVG templates). After adding, renaming or deleting one of those files, regenerate the list and commit it with your change:

bun run gen:exports

bun run dev does it for you on every start. When the list is out of date, the bot warns at startup with Stale exports (...), and the new files are not loaded until you regenerate it. bun run check:exports only checks, and exits with an error when the list is out of date.

Shard bundle

On every start, iHorizon compiles its own code once into dist/shard/bot.js (with bot.js.map, so error stack traces still point at the src/ files), then every shard starts from that single file. Dependencies are still loaded from node_modules. The folder is rebuilt on each start, never commit it.

To run the shards straight from src instead (to debug a build problem, for example), start the bot with IHORIZON_NO_BUNDLE=1. If the build fails, the bot logs the error and falls back to src on its own.

Command logs

Every command used on your servers (slash commands, context menus and prefix commands) is logged in the database, in the slash_logs table: date, server, channel, user, command and its options. Logs are kept 90 days, then deleted automatically; each shard writes its own records, so none get lost when several shards run at once.

Before the November 2026 update, they were kept in src/files/slash.log.json. On its first start, the bot moves that file into the database and renames it slash.log.json.migrated; you can delete it afterwards.