Skip to content
GitHub

OnShutdown

interface in meocord/interface Since 4.1.0

interface OnShutdown

A controller, service or provided value that cleans up before the bot stops, such as closing a connection.

Implement it to stop what OnReady started: timers, open connections, writes still buffered.

Examples

TypeScript
import { appendFile } from 'node:fs/promises'

@Service()
export class AuditLog implements OnShutdown {
  private readonly pending: string[] = []

  record(line: string) {
    this.pending.push(line)
  }

  // Writes what is still buffered before the process exits
  async onShutdown() {
    await appendFile('audit.log', this.pending.splice(0).map(line => `${line}\n`).join(''))
  }
}

Members

onShutdown

onShutdown(): Promise<void> | void

Runs before the client is destroyed.

Returns

Promise<void> | void

See also