# Tooling

Configure a seedcord project through its two config files, one for the CLI and one for your bot, and look up every CLI key.

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://seedcord.org/docs/packages/gateway/latest/classes/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`](https://seedcord.org/guide/tooling/dev/)            | runs your bot, reloads a changed file in place, and prints its logs in a terminal you can filter |
| [`seedcord codegen`](https://seedcord.org/guide/tooling/codegen/)    | imports your bot and command files, then writes `seedcord-gen.d.ts` into `root`                  |
| [`seedcord build`](https://seedcord.org/guide/tooling/build/)        | compiles `src` and writes a bootstrap file beside it                                             |
| [`seedcord commands`](https://seedcord.org/guide/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 links to 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](https://seedcord.org/guide/components/)                         |
| `bot.commands`      | the folder seedcord scans for commands                                                                                        | [Commands](https://seedcord.org/guide/commands/)                             |
| `bot.emojis`        | the emoji names [`Emojis`](https://seedcord.org/docs/packages/gateway/latest/variables/emojis) resolves at startup            | [Components](https://seedcord.org/guide/components/)                         |
| `bot.events`        | the folder seedcord scans for event handlers. Gateway only                                                                    | [Events](https://seedcord.org/guide/events/)                                 |
| `bot.clientOptions` | passed straight to the discord.js `Client`. Gateway only                                                                      | [Your first bot](https://seedcord.org/guide/first-bot/)                      |
| `subscribers`       | the folder seedcord scans for bus subscribers                                                                                 | [The bus](https://seedcord.org/guide/events/bus/)                            |
| `errors`            | how a fault renders, what gets logged, which api error codes get ignored                                                      | [Tuning error behavior](https://seedcord.org/guide/replying/error-behavior/) |
| `notifications`     | the contact name in the generic unknown-error message                                                                         | [Faults](https://seedcord.org/guide/replying/faults/)                        |
| `botColor`          | the accent on every [`BuilderComponent`](https://seedcord.org/docs/packages/core/latest/classes/builder-component) you build  | [Components](https://seedcord.org/guide/components/)                         |
| `ownerIds`          | the ids [`OwnerOnly`](https://seedcord.org/docs/packages/core/latest/functions/owner-only) treats as owners                   | [Gates](https://seedcord.org/guide/checks/gates/)                            |
| `store`             | a durable store for framework state. The default keeps it in memory and loses it on restart                                   | [The rate limiter](https://seedcord.org/guide/checks/rate-limiter/)          |
| `logger`            | the level, the sinks, and the per-channel overrides                                                                           | [Configuring the logger](https://seedcord.org/guide/tooling/logger-config/)  |
| `lifecycle`         | `shutdownDeadline`, how long shutdown may take                                                                                | [The lifecycle](https://seedcord.org/guide/plugins/lifecycle/)               |
| `runtime`           | `'server'` for a node process, `'edge'` for a bundled isolate like a Cloudflare Worker. A gateway bot only accepts `'server'` | [Building](https://seedcord.org/guide/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](https://seedcord.org/guide/tooling/dev/) runs your bot while you edit it. An http bot also needs [a tunnel](https://seedcord.org/guide/tooling/tunnel/) before Discord can reach it on your machine.
