DocsBest practices
Keeping your bot online 24/7
Handle crashes, reconnects and restarts gracefully.
Best practices 6 min read
DIGITALYCloud restarts your process automatically when it crashes, but the best bots rarely crash in the first place. These habits will keep yours stable.
Never let an error kill the process
An unhandled promise rejection stops Node.js. Log it instead, so you can fix the cause without losing uptime.
index.js
process.on('unhandledRejection', (err) => {
console.error('ERROR unhandled rejection', err);
});
client.on('error', (err) => console.error('ERROR client', err));
client.on('shardDisconnect', () => console.warn('WARN shard disconnected, reconnecting'));Shut down cleanly
When you deploy or restart, we send a SIGTERM signal and wait up to 10 seconds. Use that time to close connections and save state.
js
process.on('SIGTERM', async () => {
console.log('Shutting down...');
await db.close();
client.destroy();
process.exit(0);
});Respect rate limits
Sending too many requests to Discord gets your bot temporarily blocked. Batch updates, avoid editing the same message in a loop and let the library queue requests for you.
Stability checklist
- Errors are caught and logged, never thrown at the top level.
- The bot handles SIGTERM and closes its connections.
- Only the intents you really use are enabled.
- Long tasks run in the background instead of blocking commands.
- You have tested a restart and the bot comes back on its own.
Was this article helpful?