UNPKG

dis-warden

Version:

An enterprise-grade monitoring and management solution for Discord.js bots, with modular features and multi-webhook support.

173 lines (127 loc) 5.91 kB
# Dis-Warden 🛡️ **Dis-Warden** is a comprehensive, enterprise-grade monitoring and management solution for your Discord.js bot. With a fully modular design, you can toggle features on or off and direct notifications to different webhooks, giving you complete control over your bot's operational intelligence. Keep a watchful eye on your bot's stability, resource consumption, and guild interactions with beautiful, real-time notifications delivered exactly where you want them. 📨 ## Features ✨ #### Core Monitoring & Alerts - 🚀 **Advanced Error Detection**: Captures `uncaughtException` and `unhandledRejection` events. Can be toggled and sent to a specific errors channel. - 🔔 **Status Notifications**: Get instant alerts when your bot comes **online**, goes **offline**, or **crashes**. Fully configurable. - 🖥️ **Resource Monitoring**: Tracks CPU and memory usage, with alerts for high load and latency. Can be disabled or routed to a performance channel. - 📊 **Guild Activity Tracking**: Logs when your bot joins or leaves a server. Can be toggled and sent to a guild-management channel. #### Performance Management - ⚙️ **Automatic Rate Limiting**: Identify and rate-limit users consuming excessive resources. -**Optimized & Tweaked**: The entire codebase is optimized for minimal performance impact. #### Developer Experience - 🛠️ **Modular & Configurable**: Enable only the features you need. - 🔗 **Multi-Webhook Support**: Use a different webhook for each feature, or a single global one. - 🎨 **Customizable Embeds**: Tailor the look and feel of every notification. ## Installation 📦 Install Dis-Warden using your preferred package manager: ```bash npm install dis-warden # or yarn add dis-warden # or pnpm add dis-warden ``` ## Setup & Usage 🛠️ ### 1\. Basic Initialization (Single Webhook) For a simple setup, provide a global `webhookUrl` that all enabled features will use. ```javascript const { Client, GatewayIntentBits } = require('discord.js'); const Warden = require('dis-warden'); const client = new Client({ intents: [ /* ... your intents ... */ ] }); const warden = new Warden(client, { // A single webhook for all notifications webhookUrl: 'YOUR_GLOBAL_DISCORD_WEBHOOK_URL', // You can still disable features you don't need resourceMonitoring: { enabled: false } }); // Activate all enabled monitoring services warden.watch(); client.login('YOUR_DISCORD_BOT_TOKEN'); ``` ### 2\. Advanced Initialization (Multi-Webhook) Assign a unique webhook to each feature for granular notification routing. If a feature's `webhookUrl` is not set, it will fall back to the global `webhookUrl`. ```javascript const warden = new Warden(client, { // Global fallback webhook (optional if all features have their own) webhookUrl: 'YOUR_FALLBACK_WEBHOOK_URL', // --- Send errors to the #errors channel --- errorLogging: { enabled: true, webhookUrl: 'YOUR_ERRORS_WEBHOOK_URL' }, // --- Send status updates to the #status channel --- statusMonitoring: { enabled: true, webhookUrl: 'YOUR_STATUS_WEBHOOK_URL', onlineMessage: '✅ **Bot is Online** - All systems operational.' }, // --- Send resource alerts to the #performance channel --- resourceMonitoring: { enabled: true, webhookUrl: 'YOUR_PERFORMANCE_WEBHOOK_URL', pollingInterval: 60000, // Check every 60 seconds thresholds: { cpu: 80, memory: 85, latency: 500 } }, // --- Send guild join/leave logs to the #guild-logs channel --- guildTracking: { enabled: true, webhookUrl: 'YOUR_GUILD_LOGS_WEBHOOK_URL' }, // --- Disable performance management --- performanceManagement: { analytics: false, rateLimiter: { enabled: false } } }); // Activate all the features configured above warden.watch(); client.login('YOUR_DISCORD_BOT_TOKEN'); ``` ### 3\. Manually Logging Errors Manually logged errors will be sent to the webhook defined in the `errorLogging` configuration block. ```javascript client.on('interactionCreate', async (interaction) => { if (!interaction.isCommand()) return; try { // Some risky operation } catch (error) { // This will go to your errorLogging.webhookUrl warden.logError(error, { title: 'Custom error title' }); // ... } }); ``` ## API Reference 📚 ### `new Warden(client, options)` Creates a new Warden instance. - `client` (Client): Your `discord.js` client instance. - `options` (Object): The configuration object. - `webhookUrl` (String): **Optional.** A global fallback webhook URL. - `errorLogging` (Object): - `enabled` (Boolean): Default `true`. - `webhookUrl` (String): Specific webhook for errors. - `statusMonitoring` (Object): - `enabled` (Boolean): Default `true`. - `webhookUrl` (String): Specific webhook for status. - `resourceMonitoring` (Object): - `enabled` (Boolean): Default `true`. - `webhookUrl` (String): Specific webhook for alerts. - `guildTracking` (Object): - `enabled` (Boolean): Default `true`. - `webhookUrl` (String): Specific webhook for guild logs. ### `warden.watch()` Activates all monitoring services where `enabled: true`. ### `warden.logError(error, [options])` Manually logs an error. It will use the webhook specified in `errorLogging`. ## Contributing 🤝 Contributions are welcome\! Feel free to submit issues or pull requests to improve Dis-Warden. ## License 📄 This project is licensed under the MIT License.