# Seedcord

`class` in `http` · v0.11.0

<https://seedcord.org/docs/packages/http/0.11.0/classes/seedcord>

The HTTP-interactions bot on node. `start()` loads handlers from `config.bot.interactions.path`
and binds a server on `port`. With `port: false`, your own server passes requests to `fetch()`.

Shutdown waits up to 5s for interactions that are still running.

```ts
class Seedcord extends ServerHost<"http"> implements SeedcordInstance
```

## Constructors

### constructor

```ts
Seedcord(config: HttpServerConfig)
```

Constructs a new instance of the `Seedcord` class

## Properties

### applicationId

```ts
public get applicationId(): string
```

The bot's Discord application id. Throws if you read it before the Configuration phase.

### bus

```ts
public readonly bus: Bus
```

### config

```ts
public readonly config: HttpServerConfig
```

### port

```ts
public get port(): number | undefined
```

The bound server port, set once `start()` is listening. Stays `undefined` with `port: false`.

### rateLimiter

```ts
public readonly rateLimiter: IRateLimiter
```

### rest

```ts
public readonly rest: REST
```

Discord REST client built from `bot.restOptions`. `start()` sets the token.

### shutdown

```ts
readonly shutdown: Pick<CoordinatedShutdown, 'addTask'>
```

Add a task that runs while the bot shuts down.

### startup

```ts
readonly startup: Pick<CoordinatedStartup, 'addTask'>
```

Add a task that runs while the bot starts.

### username

```ts
public get username(): string | undefined
```

The bot's discord username, populated by the ready fetch.

## Methods

### [Symbol.asyncDispose]

```ts
async [Symbol.asyncDispose](): Promise<void>
```

Runs the coordinated shutdown without calling `process.exit`. A new `Seedcord` can be
constructed afterwards. `await using` calls this when its scope ends.

### attach

```ts
attach<Key, Ctor>(
    this: this,
    key: AttachKeyAssert<Key, this>,
    Plugin: AttachableCtor<Ctor, BotT, BotRt>,
    args: PluginArgs<Ctor>
): this & Attached<Key, InstanceType<Ctor>>
```

Attaches a plugin under `key`. Read the instance back as `core[key]`. `seedcord codegen`
writes the `Core` augmentation that types it there.

Put one dot in the key to nest the plugin under a group. `'services.users'` reads back as
`core.services.users`. Each name holds one plugin or one group.

Startup runs each plugin's `init()` in attach order within its phase. A node bot starts in
`start()`. An edge bot starts on its first request.

Attaching a plugin whose `transport` or `runtime` differs from this host fails to compile.
Your constructor takes `CoreBase` as its first parameter (you don't need to pass it though).
A narrower one fails to compile here.

### fetch

```ts
public async fetch(request: Request): Promise<Response>
```

Answers one request to the interactions endpoint. Mount it in your own server when the
config sets `port: false`.

Rejects with `CoreFetchBeforeStart` until `start()` is called. A request that arrives while
`start()` runs waits for all of startup, the command deploy included. Answers 503 once
shutdown begins or `start()` fails.

### start

```ts
public async start(): Promise<this>
```

Starts the host and runs the startup tasks.
