Skip to content

Configuration

You are now ready to configure your self-hosted iHorizon bot. This step involves filling in the .env file to provide your Discord bot token and customize other options.

iHorizon reads its whole configuration from environment variables. Bun loads them on its own from a .env file at the root of the project, so there is no configuration file to edit in the source code.

Editing the .env File

From the root of the project, copy the documented template to .env:

cp .env.example .env

Open .env and put your Discord bot token in BOT_TOKEN:

.env
# --- Discord ---
BOT_TOKEN="your-bot-token"

.env is ignored by Git, so your token and passwords never end up in a commit. If you installed the bot with the iHorizon Provisioning Script, it has already written this file for you (with SQLite or PostgreSQL as the database), and you only need to edit it to change a value.

Writing values

A few rules apply to every line of the file:

  • One variable per line, written NAME=value. Put values that contain spaces or # between double quotes. Lines starting with # are comments.
  • Lists (OWNERS, ALWAYS_100, several Lavalink nodes) are comma-separated: OWNERS="123456789012345678,987654321098765432".
  • Booleans of the bot configuration (the variables in the tables below) accept true / false, as well as 1 / 0, yes / no and on / off. Anything else, such as a typo, is refused at startup instead of being guessed. The variables listed under Other variables only understand the exact value shown.
  • Empty values fall back to the default listed in the tables below.
  • Connection settings are URLs (LAVALINK_URL, DATABASE_URL). Special characters inside a password or a user name must be percent-encoded: @ is %40, : is %3A, / is %2F, # is %23 and $ is %24. For instance, the password p@ss:word becomes p%40ss%3Aword.

Dollar signs, quotes and backslashes

Bun expands $NAME as a reference to another variable, even inside double quotes. A literal $ has to be written \$, or avoided (inside a URL, percent-encode it as %24). A " or a backslash cannot be stored exactly in a value: avoid them in tokens and passwords.

Configuration Options

The file is split into sections, one per area of the bot. Only BOT_TOKEN has to be filled in: the bot refuses to start without it. Every other variable changes how iHorizon behaves once it is online.


Discord

Variable Format Required Default
BOT_TOKEN Text Yes
PHONE_PRESENCE Boolean No false
MESSAGE_COMMANDS_MENTION Boolean No true
DEFAULT_PREFIX Text No ?

BOT_TOKEN is the bot token you copied from the Discord Developer Portal.

With MESSAGE_COMMANDS_MENTION set to true, message commands are triggered by mentioning the bot. Set it to false if you prefer a classic prefix, and put that prefix in DEFAULT_PREFIX.

.env
BOT_TOKEN="your-bot-token"
MESSAGE_COMMANDS_MENTION=false
DEFAULT_PREFIX="!"
PHONE_PRESENCE=false

PHONE_PRESENCE

Setting PHONE_PRESENCE to true displays the bot's online status as if it were connected from a phone:

Phone status on the iHorizon profile


Owners

Variable Format Required Default
OWNERS Comma-separated user IDs No empty

OWNERS defines which users are authorized to perform blacklisting and unblacklisting actions, or execute the /eval command (which lets you run JavaScript code directly on your self-hosted bot).

These owners also have more rights than the owners added later through the database: an owner from the database cannot unowner, blacklist or ban them.

.env
OWNERS="123456789012345678,987654321098765432"

Variable Format Required Default
LAVALINK_URL Comma-separated node URLs No no node
LAVALINK_LOGS_CHANNEL_ID Channel ID No empty

LAVALINK_URL lists the Lavalink servers used for music playback, one URL per node:

ws://password@host:port
  • The node password goes before the @. Lavalink has no user name, so nothing else is needed.
  • ws:// (or http://) connects in plain text, wss:// (or https://) over TLS.
  • The port defaults to 2333, or 443 with TLS.
  • Optional query parameters: id (a name of your choice, the host name by default), retryAmount and retryDelay.

Several nodes go on the same line, separated by commas:

.env
LAVALINK_URL="ws://youshallnotpass@localhost:2333?id=main,wss://p%[email protected]?id=backup&retryAmount=5"
LAVALINK_LOGS_CHANNEL_ID="123456789012345678"

LAVALINK_LOGS_CHANNEL_ID receives the errors thrown by Lavalink.

Music commands stay silent until at least one node is reachable. iHorizon talks to its nodes through the Lavalink protocol, so any Lavalink-compatible server works; the official instance runs Wavyzon, iHorizon's own Rust audio backend.


Database

Variable Format Required Default
DATABASE_URL Driver name or URL No sqlite

DATABASE_URL selects where iHorizon stores its data:

Value Storage
sqlite A SQLite file, src/files/db.sqlite. This is the default.
json A JSON file, src/files/db.json.
memory RAM only: the data is lost as soon as the bot stops.
postgres://user:password@host:5432/database A PostgreSQL server. The port defaults to 5432.
ws://login:password@host:port A HorizonDB server.

For HorizonDB, the credentials are optional (ws://127.0.0.1:8080), and you can append ?requestTimeoutMs=10000 to override the default request timeout.

.env
# PostgreSQL, with the password "s3cret#1" percent-encoded
DATABASE_URL="postgres://ihorizon:s3cret%[email protected]:5432/ihorizon"

Any other value is refused at startup, instead of falling back to sqlite.

Backing up a SQLite database

SQLite runs in WAL mode, so that every shard can write at the same time: the latest writes sit in src/files/db.sqlite-wal (with db.sqlite-shm) until SQLite merges them into db.sqlite. To back the database up, stop the bot first, or copy the three files together.


Core

Variable Format Required Default
DEV_MODE Boolean No false
BLACKLIST_PICTURE_URL URL No empty
GUILD_LOGS_CHANNEL_ID Channel ID No empty
REPORT_CHANNEL_ID Channel ID No empty
SHARD_LOGS_CHANNEL_ID Channel ID No empty

With DEV_MODE set to true, errors are printed in the console. Set it to false and they are written to the .err.logs folder instead.

BLACKLIST_PICTURE_URL takes the URL of a .png image, shown in the embed a blacklisted user receives when they try to interact with the bot.

The channel IDs decide where the bot reports what happens to it: GUILD_LOGS_CHANNEL_ID receives a message when the bot joins or leaves a server, and REPORT_CHANNEL_ID receives the bugs users report through the bot. Lavalink errors go to LAVALINK_LOGS_CHANNEL_ID, described above. SHARD_LOGS_CHANNEL_ID receives the life of each shard in short lines: ready, reconnecting, resumed, disconnected, died. A "reconnecting" followed by "resumed" is normal (Discord moves its connections now and then); one without "resumed" deserves a look.

.env
DEV_MODE=false
BLACKLIST_PICTURE_URL="https://example.com/blacklisted.png"
GUILD_LOGS_CHANNEL_ID="123456789012345678"
REPORT_CHANNEL_ID="123456789012345678"
SHARD_LOGS_CHANNEL_ID="123456789012345678"

Commands

Variable Format Required Default
ALWAYS_100 Comma-separated pairs No empty

ALWAYS_100 lists the pairs of users whose /love score is always 100%. Write each pair as {USER_ID_ONE}x{USER_ID_TWO}, and leave it empty if you do not need it.

.env
ALWAYS_100="123456789012345678x987654321098765432"

HorizonGateway

Variable Format Required Default
HORIZON_GATEWAY_URL URL No https://gateway.ihorizon.org
HORIZON_GATEWAY_LOCAL_URL URL No empty
HORIZON_API_TOKEN Text No empty
TICKET_TRANSCRIPT_URL URL No empty

These variables connect the bot to HorizonGateway, the private-source service behind the official instance. A self-hosted bot does not need it, and you can leave them as they are in .env.example.

HORIZON_GATEWAY_URL is the public gateway URL, used for the links shown to users (OAuth2, backups...). HORIZON_GATEWAY_LOCAL_URL is an optional gateway URL on the same machine, used for the bot's own calls such as image rendering; it skips reverse proxies and their body limits. Leave it empty to use HORIZON_GATEWAY_URL for everything.

HORIZON_API_TOKEN is the private key shared between the bot and the gateway, for instance for the requests behind the /authrestore commands. Choose a strong value and keep it private.

TICKET_TRANSCRIPT_URL is the gateway site that shows ticket transcripts (<url>/<channelId>, e.g. https://ticket.ihorizon.org). When set, closed and deleted tickets are kept in the database and their messages get a link to that page. Empty: the official bot (production branch with HORIZON_API_TOKEN) uses https://ticket.ihorizon.org; any other instance only sends transcripts as HTML files.

.env
HORIZON_GATEWAY_URL="https://gateway.ihorizon.org"
HORIZON_GATEWAY_LOCAL_URL="http://127.0.0.1:31981"
HORIZON_API_TOKEN="a-long-random-secret"
TICKET_TRANSCRIPT_URL="https://ticket.ihorizon.org"

Images are rendered without a browser

Every image (rank and welcome cards, captchas, statistics...) is an SVG template rendered with resvg. When a gateway is configured, the bot sends the rendering to it; without one, or while the gateway is unreachable, it renders locally with the bundled resvg. Either way, no Chrome or Chromium is needed at runtime.


Last.fm

Variable Format Required Default
LASTFM_API_KEY Text No empty
LASTFM_SHARED_SECRET Text No empty

Both values come from a Last.fm API account and are only needed if you want the Last.fm scrobbler module to work. Leave them empty otherwise.


uptimeKuma

Variable Type Required
UPTIME_KUMA_URL String No
UPTIME_KUMA_API_KEY String No
UPTIME_KUMA_GROUPS Comma-separated list No

Feeds the +status-embed panel from an Uptime Kuma status page. UPTIME_KUMA_URL is the public page (https://host/status/<slug>). The API key reads /metrics and adds the 30 day uptime. UPTIME_KUMA_GROUPS keeps only the named groups of the page, and an empty value shows them all. Without a URL, the panel uses the bot's own checks.


Other Variables

The end of .env.example holds optional variables that most self-hosted bots can leave untouched:

  • Notifiers and integrations: TWITCH_APPLICATION_ID and TWITCH_APPLICATION_SECRET (Twitch notifier), YOUTUBE_API_KEY (YouTube notifier), KICK_CLIENT_ID and KICK_CLIENT_SECRET (Kick notifier, from a Kick developer app; the Bluesky and Mastodon notifiers need no key), GITHUB_API_KEY (GitHub API requests) and DB_STATS_CHANNEL.
  • Sharding: TOTAL_SHARDS forces the number of shards (auto lets the bot work it out from Discord's recommendation). IHORIZON_NO_BUNDLE=1 runs the shards from the source code instead of the dist/shard bundle.
  • Mail: SMTP_HOST, SMTP_PORT, SMTP_SECURE, SMTP_USER, SMTP_PASS, OWNER_MAIL and EMAIL_WHEN_CHANGE_GUILD configure the emails the bot sends to its owner.
  • Changelog PDF tool: PUPPETEER_SKIP_CHROMIUM_DOWNLOAD and PUPPETEER_EXECUTABLE_PATH are only read by the release tool tools/ChangelogPdf.ts, never by the bot itself.

Migrating from config.ts

Older installs kept their configuration in src/files/config.ts. That file still works: as long as it exists, the bot reads its settings from it instead of .env (except BOT_TOKEN, LASTFM_API_KEY and LASTFM_SHARED_SECRET, which already took precedence when set in .env), and logs a deprecation warning at startup.

Move it into .env with a single command, from the root of the project:

bun run config:env

The migration:

  • keeps the variables already set in .env, and adds the others from config.ts;
  • keeps the comments and the other lines of your .env;
  • reads the result back and checks it before replacing your .env: if a value cannot be stored exactly, the migration stops and config.ts stays in place;
  • moves config.ts to config.ts.migrated at the project root once it succeeds (with a date if an earlier migration left one). Git ignores it, since it still holds your secrets.

No value is ever printed, so the command is safe to run in a shared terminal. Once the bot starts without the warning, you can delete config.ts.migrated: it is only a backup.

Finalizing

Once .env is filled in, there is nothing to rename or compile: the bot reads it at every start, as long as it is started from the root of the project.

You are now ready to start the bot! Continue to Starting the Bot.