Skip to content
GitHub

MeoCordApplication

interface in meocord/core and meocord/interface Since 4.1.0

interface MeoCordApplication

The application MeoCordFactory.create returns: a bot in one process, or the manager of a process per shard.

main.ts starts it and nothing else needs it: which of the two it is follows from meocord.config.ts's sharding, and both start and register commands the same way.

Examples

TypeScript
@MeoCord({ controllers: [], clientOptions: { intents: [GatewayIntentBits.Guilds] } })
class App {}

const app: MeoCordApplication = MeoCordFactory.create(App)
await app.start()

Members

start

start(): Promise<void>

Starts the bot: resolves its providers and logs in, or with process sharding, spawns the shards, each of which does so.

A call while one is under way waits for it, and a call once the bot is online does nothing. Retrying it after a failed login is deprecated; in the next major version (5.0) it rejects. Use MeoCordFactory.create to make a new app instead. A retry after a provider's factory failed stays supported.

A shard whose start fails exits 1 once the rejection is handled, and its manager restarts it. When the failure is one every shard would meet, MeoCord refusing the app or Discord refusing the login for good (an invalid token, or intents it disallows or does not know), the manager logs why, stops every shard and exits 1 instead.

Returns

Promise<void>

A promise that resolves once the bot is logged in, or every shard has been spawned. With process sharding, it also resolves when stop() ends the start, which then spawns no more shards.

Throws

  • For a bot in one process, the error of a provider's factory that failed, or the login error, such as an invalid token; it also rejects when stop() ends the start, once the stop is done with the onShutdown hooks of what the start made: they have finished, or shutdownTimeout has ended the wait for them. A start still awaiting a provider's factory when the stop stops waiting for it rejects once that factory settles, after the stop has resolved and the value the factory returned is shut down. In either mode, a start of an app already stopped rejects.

stop

stop(): Promise<void>

Stops the bot: stops taking events, waits for the calls under way, runs the onShutdown hooks under the configured shutdownTimeout and closes the client, or with process sharding, asks every shard to shut down and waits for it. It ends no process of its own accord, except that called in a shard, it asks the manager to stop every shard, which then shuts that shard's process down too. A call that awaits stop(), as an owner-only shutdown command does, is not waited for. A stop() called while an onShutdown hook of the stop under way runs, by the hook or by work it started, awaited or not, gets a promise that resolves at once: the stop it asks for is the one running the hook, which goes on once the hook returns. One called after the hook has returned waits for the whole stop.

A stop while the bot starts ends that start: it waits for the providers being made, at most shutdownTimeout, and nothing more is made after it. What the start made is shut down by the rule OnShutdown gives; for a bot in one process, the start then rejects, and the stop resolves after it. A start whose provider's factory outlasts that wait is the exception: the stop resolves without it, and the start rejects once the factory settles. The value that factory returns is shut down as it arrives, by its own onShutdown, within shutdownTimeout, unless it has an onReady hook: that never ran, so by the same rule it gets no onShutdown. What it injects is shut down already, so its onShutdown may find that closed. A call after the first waits for it, and a stopped app does not start again.

Returns

Promise<void>

A promise that resolves once the bot is stopped. It never rejects: a failure to close is logged, and sets process.exitCode to 1 unless another code is already set.

registerCommands

registerCommands(): Promise<void>

Registers the application's commands with Discord, where meocord.config.ts's commands says. A failure is logged rather than thrown.

For a bot in one process, it needs the bot online, as the application comes from the login; called earlier, it logs a warning and registers nothing. With process sharding, the manager registers over REST, before or after start().

Returns

Promise<void>

See also