discord.js-anticrash
v5.2.5
Published
Advanced anticrash, customizable, and error-handling enhancements for Discord bots.
Downloads
59
Maintainers
Readme
discord.js-anticrash
: ⚡ Powerful Error Handling for Discord.js
discord.js-anticrash is a lightweight and efficient package designed to enhance the stability of your Discord bot built with Discord.js. It automatically handles errors and crashes to ensure your bot stays online and operational with minimal downtime.
Table of Contents
Features
- Automatic Error Recovery: Automatically restarts your bot if it crashes due to uncaught exceptions or unhandled promise rejections.
- Customizable Logging: Easily log errors and events to your preferred logging service or console for better monitoring.
- User-Friendly API: Simple to integrate and use with your existing Discord.js bot setup.
Installation
To install discord.js-anticrash, use the following command:
npm install discord.js-anticrash
Usage
Here's a simple example of how to integrate discord.js-anticrash into your bot:
const { Client } = require('discord.js');
const Anticrash = require('discord.js-anticrash');
const client = new Client();
Anticrash(client); // Enable anti-crash features
client.once('ready', () => {
console.log(`Logged in as ${client.user.tag}`);
});
client.login('YOUR_BOT_TOKEN');
TypeScript & ES Modules Usage
For TypeScript or ES Modules (.mjs
), you can import and use the package like this:
import { Client } from 'discord.js';
import Anticrash from 'discord.js-anticrash';
const client = new Client();
Anticrash(client); // Enable anti-crash features
client.once('ready', () => {
console.log(`Logged in as ${client.user.tag}`);
});
client.login('YOUR_BOT_TOKEN');
API Reference
Anticrash(client: Client): void
- Description: Initializes the anti-crash features for your Discord.js client.
- Parameters:
client
: The instance of your Discord.js client.
- Returns: Nothing.
Error Handling
discord.js-anticrash provides robust error handling. When an error occurs, it logs the error message and stack trace for easier troubleshooting.
Example of a logged error:
✖ ERROR: Unhandled Promise Rejection
└─ Stack Trace:
Error: Some error message
License
This project is licensed under the MIT License. See the LICENSE file for more details.
Contributing
Contributions are welcome! If you'd like to help improve discord.js-anticrash, please open an issue or submit a pull request on GitHub. All contributions should follow coding best practices and include relevant test cases.
Acknowledgments
- Discord.js - A powerful JavaScript library for interacting with the Discord API.
- Special thanks to everyone who has contributed to this package!