Skip to content
Classhttpworkerdv0.11.0

Seedcord

The HTTP-interactions bot on Cloudflare Workers. Default-export it from bot.ts. Cloudflare calls fetch for every request.

The constructor stores the config. The first POST in each isolate reads DISCORD_BOT_TOKEN and the public key, command ids, and emoji ids that seedcord build wrote into the worker. It loads the handler and subscriber folders, then runs the startup tasks and every plugin's init() and ready(). Requests that arrive meanwhile wait for it.

Under seedcord dev the bot starts when the CLI starts it. It reads the public key and emoji ids from Discord and deploys your commands, the way a node bot does.

class Seedcord extends PluginHost<"http", "edge">

Member visibility

Filter class members by access level.

constructor

Constructs a new instance of the Seedcord class

Seedcord(config: HttpEdgeConfig)

Showing members with Protected visibility and higher.

applicationId

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

public get applicationId(): string

bus

public readonly bus: Bus

See also:Bus

rest

Discord REST client built from bot.restOptions, with both sweepers off.

public readonly rest: REST

Cloudflare Workers don't provide a shutdown hook.

shutdown

public readonly shutdown: Pick<import("@seedcord/core/node").CoordinatedShutdown, "addTask">

Throws:

  • A SeedcordError with CoreLifecycleUnavailable every time you call addTask.

Deprecated

startup

Add a task that runs during startup, on the first POST.

public readonly startup: Pick<CoordinatedStartup, 'addTask'>

attach()

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.

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

Also the channel the plugin logs on, dots included.

Parameter: args

Whatever your constructor takes after the host.

Throws:

A SeedcordError when you attach after the bot has started.

Throws:

A SeedcordTypeError when key is taken, reserved, or malformed.

Throws:

A SeedcordTypeError when the plugin extends Plugin from another copy of @seedcord/core.

Throws:

A SeedcordTypeError when the plugin's transport or runtime differs from this host and the types were bypassed.

Inherited from:PluginHost

fetch()

Answers one request to the interactions endpoint. Cloudflare passes env and ctx, but this method reads only ctx. Import your bindings as env from cloudflare:workers. cf workers types writes their types. Work that continues after the 202 response runs under ctx.waitUntil. Any request besides a POST gets a 405 before the bot starts.

public async fetch(
    request: Request,
    _env?: unknown,
    ctx?: EngineContext
): Promise<Response>