OnShutdown
interface in meocord/interface Since 4.1.0
interface OnShutdownA 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
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> | voidRuns before the client is destroyed.
Returns
Promise<void> | voidSee also
- OnReady
- Lifecycle hooks