OnReady
interface in meocord/interface Since 4.1.0
interface OnReadyA 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
@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> | voidRuns once the client is ready.
Parameters
| Name | Type | Description |
|---|---|---|
client | Client<true> | The ready Discord client. |
info | ReadyInfo | Facts about this process, such as whether it should do one-off work. |
Returns
Promise<void> | voidSee also
- OnShutdown
- Lifecycle hooks