Skip to content
GitHub

OnReady

interface in meocord/interface Since 4.1.0

interface OnReady

A controller, service or provided value that does work once the bot is online, such as starting timers.

Implement it for work that needs the ready client: a scheduler, a warmed cache, the bot's activity. For work in response to Discord, use @On with a client event instead; to clean up, implement OnShutdown.

Examples

TypeScript
@Service()
export class ServerCountReporter implements OnReady, OnShutdown {
  private readonly logger = new Logger(ServerCountReporter.name)
  private timer?: NodeJS.Timeout

  onReady(client: Client<true>, { primary }: ReadyInfo) {
    // One process reports, however many shards run
    if (primary) this.timer = setInterval(() => this.logger.log(`${client.guilds.cache.size} servers`), 60_000)
  }

  onShutdown() {
    clearInterval(this.timer)
  }
}

Members

onReady

onReady(client: Client<true>, info: ReadyInfo): Promise<void> | void

Runs once the client is ready.

Parameters

NameTypeDescription
clientClient<true>

The ready Discord client.

infoReadyInfo

Facts about this process, such as whether it should do one-off work.

Returns

Promise<void> | void

See also