# Tooling

Configure a seedcord project through its two config files, one for the CLI and one for your bot. Covers every key in seedcord.config.ts, the commands that read it, and where each key of your bot's own config gets taught.

A seedcord project has two config files, because two different programs read them. `seedcord dev` and `seedcord codegen` have to import your bot before it runs, so they need its path from somewhere other than the bot itself. `seedcord.config.ts` holds those paths for the CLI. The `new Seedcord({ ... })` call in `src/bot.ts` configures the bot while it runs.

The CLI looks for `seedcord.config.ts` or `seedcord.config.mts` in the directory you run it from.

```ts title="seedcord.config.ts"
import { defineConfig } from 'seedcord';

export default defineConfig({
    root: './src',
    instance: './bot.ts',
    entry: './index.ts',
    // false stops the dev terminal's idle animation
    idleAnimation: true,
    build: {
        tsconfig: './tsconfig.build.json'
    },
    hmr: {
        // true runs tsc --watch beside the bot, in a second node process
        typecheck: false
    }
});
```

You have to write `instance` and `entry`. Every other key has a default.

{/* prettier-ignore-start */}

| key             | default                 | what it does                                                                                                                                             |
| --------------- | ----------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `instance`      | required                | the module whose default export is your configured [`Seedcord`](https://docs.seedcord.org/packages/gateway/latest/seedcord)                              |
| `entry`         | required                | the file that starts the bot, and the one the build copies                                                                                               |
| `root`          | the config's own folder | the folder `instance` and `entry` resolve against                                                                                                        |
| `tunnel`        | `true`                  | `true` opens a cloudflared quick tunnel to your http bot, and `false` turns it off. An https string is a URL you already serve. A gateway bot ignores it |
| `idleAnimation` | `true`                  | whether the dev terminal animates while nothing happens                                                                                                  |
| `build`         | `{}`                    | `outDir` (default `dist`), `tsconfig`, and `bootstrap` for `seedcord build`, resolved against the config's folder                                        |
| `hmr`           | omitted                 | `restart` globs, `rollback`, and `typecheck` for `seedcord dev`                                                                                          |

{/* prettier-ignore-end */}

`entry` has to resolve inside `root`. A path outside it throws `CliConfigEntryOutsideRoot`.

## The commands

A project from `create-seedcord` has `dev`, `codegen`, and `build` as scripts in its `package.json`, and all three read the config above.

{/* prettier-ignore-start */}

| command                                   | what it does                                                                                     |
| ----------------------------------------- | ------------------------------------------------------------------------------------------------ |
| [`seedcord dev`](/tooling/dev)            | runs your bot, reloads a changed file in place, and prints its logs in a terminal you can filter |
| [`seedcord codegen`](/tooling/codegen)    | imports your bot and command files, then writes `seedcord-gen.d.ts` into `root`                  |
| [`seedcord build`](/tooling/build)        | compiles `src` and writes a bootstrap file beside it                                             |
| [`seedcord commands`](/commands/deployed) | inspects and cleans up the commands Discord has registered for your bot                          |

{/* prettier-ignore-end */}

`seedcord commands` doesn't read the config. It reads `DISCORD_BOT_TOKEN` from your environment. It isn't one of the scripts either, so run it through your package manager's runner.

```sh
pnpm exec seedcord commands
```

## Your bot's config

`src/bot.ts` holds the second config, the one your bot reads. Every key gets taught on the page that needs it, inside a real `new Seedcord({ ... })` sample. The last column names that page.

`bot`, `subscribers`, `bot.interactions`, and `bot.commands` are required. A gateway bot also has to set `bot.events` and `bot.clientOptions`. Every other key is optional.

{/* prettier-ignore-start */}

| key                 | what it sets                                                                                                                  | where it's taught                                 |
| ------------------- | ----------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------- |
| `bot.interactions`  | the folder seedcord scans for handlers, plus middleware and ignored ids                                                       | [Components](/components)                         |
| `bot.commands`      | the folder seedcord scans for commands                                                                                        | [Commands](/commands)                             |
| `bot.emojis`        | the emoji names [`Emojis`](https://docs.seedcord.org/packages/gateway/latest/emojis) resolves at startup                      | [Components](/components)                         |
| `bot.events`        | the folder seedcord scans for event handlers. Gateway only                                                                    | [Events](/events)                                 |
| `bot.clientOptions` | passed straight to the discord.js `Client`. Gateway only                                                                      | [Your first bot](/first-bot)                      |
| `subscribers`       | the folder seedcord scans for bus subscribers                                                                                 | [The bus](/events/bus)                            |
| `errors`            | how a fault renders, what gets logged, which api error codes get ignored                                                      | [Tuning error behavior](/replying/error-behavior) |
| `notifications`     | the contact name in the generic unknown-error message                                                                         | [Faults](/replying/faults)                        |
| `botColor`          | the accent on every [`BuilderComponent`](https://docs.seedcord.org/packages/core/latest/builder-component) you build          | [Components](/components)                         |
| `ownerIds`          | the ids [`OwnerOnly`](https://docs.seedcord.org/packages/core/latest/owner-only) treats as owners                             | [Gates](/checks/gates)                            |
| `store`             | a durable store for framework state. The default keeps it in memory and loses it on restart                                   | [The rate limiter](/checks/rate-limiter)          |
| `logger`            | the level, the sinks, and the per-channel overrides                                                                           | [Configuring the logger](/tooling/logger-config)  |
| `lifecycle`         | `shutdownDeadline`, how long shutdown may take                                                                                | [The lifecycle](/plugins/lifecycle)               |
| `runtime`           | `'server'` for a node process, `'edge'` for a bundled isolate like a Cloudflare Worker. A gateway bot only accepts `'server'` | [Building](/tooling/build)                        |

{/* prettier-ignore-end */}

> **Gateway and http differ**
>
> Each transport package declares its own `Seedcord` and its own config type, and a few keys only exist on one of them.
>
> * An http server takes `port`, which defaults to 3000. An edge bot sets `runtime: 'edge'`, so TypeScript rejects `port` and `lifecycle` on it.
> * A gateway bot runs a small health server on port 6967 that answers `/health`. Its `healthCheck` key takes `false` to turn that off, or an object with `port`, `path`, and `host`.
> * `Emojis` resolves each name to a discord.js emoji on gateway, and to a plain resolved emoji object on http.

The reference site has the full type of every one of these, down to each nested field.

Next, [the dev terminal](/tooling/dev) runs your bot while you edit it. An http bot also needs [a tunnel](/tooling/tunnel) before Discord can reach it on your machine.
