Aidyn: Discord Bot Framework
raw JSON →Aidyn is a lightweight, class-based framework designed for rapidly building Discord bot commands, abstracting away much of the boilerplate associated with `discord.js` interaction. It is currently at version 1.1.1, indicating a relatively early but stable stage of development. While no explicit release cadence is stated, its versioning suggests a focused development approach. Key differentiators include its class-based command architecture, native TypeScript support (as the project is built in TypeScript), built-in state management for data handling between commands, and an integrated feature for automatic database backup specifically with MongoDB. It aims to let developers jump straight to business logic for their bot commands, providing a structured approach on top of `discord.js`.
Common errors
error DiscordAPIError: Missing Access ↓
BotToken in the Aidyn constructor is correct and that your bot has all necessary intents and permissions enabled in the Discord Developer Portal. error MongoServerSelectionError: connect ECONNREFUSED <IP>:<PORT> ↓
ConnectionString in the Aidyn constructor. Ensure the MongoDB server is accessible from where your bot is hosted and that no firewalls are blocking the connection. error ReferenceError: Command is not defined ↓
import { Command } from 'aidyn'; to the top of your file where you define custom commands. error TypeError: aidyn.start is not a function ↓
const aidyn = new Aidyn({...}); before calling aidyn.start(commands);. Double-check the casing and spelling of the method name. Warnings
gotcha The `Logging` parameter in the Aidyn constructor has a level `2` which is explicitly 'NOT RECOMMENDED' due to excessive verbosity. Stick to `0` for no logging or `1` for command logging to avoid performance issues or overwhelming console output. ↓
gotcha Aidyn currently supports only MongoDB for its database features, including automatic backups. If your project requires a different database system, you will need to manage its integration externally without leveraging Aidyn's built-in capabilities. ↓
gotcha The framework primarily uses modern JavaScript (ESM) import syntax. Attempting to use CommonJS `require()` syntax for core `aidyn` modules may lead to runtime errors or unexpected behavior, especially in environments configured for ESM. ↓
breaking Aidyn requires Node.js v8 LTS or higher. While this is an older version, running on unsupported or significantly older Node.js versions may lead to compatibility issues or missing features, as Discord.js and its dependencies evolve. ↓
Install
npm install aidyn yarn add aidyn pnpm add aidyn Imports
- Aidyn wrong
const { Aidyn } = require('aidyn');correctimport { Aidyn } from 'aidyn'; - Command wrong
const { Command } = require('aidyn');correctimport { Command } from 'aidyn'; - Message wrong
import { Message } from 'aidyn';correctimport { Message } from 'discord.js';
Quickstart
import { Aidyn, Command } from 'aidyn';
import { Message } from 'discord.js'; // Assuming discord.js is installed
class ExampleCommand extends Command {
static NAME = 'example';
public Name(): string {
return ExampleCommand.NAME;
}
public Namespace(): string {
return 'ExampleNamespace';
}
public async Run(message: Message): Promise<any> {
const context = this.GetContext(message); // Process message content for args/flags
return message.channel.send(`Command: %example was called with content ${JSON.stringify(context)}`);
}
}
const commands: { [key: string]: typeof Command } = {};
commands[ExampleCommand.NAME] = ExampleCommand;
// Ensure you have these environment variables set
const botToken = process.env.DISCORD_BOT_TOKEN ?? 'YOUR_BOT_TOKEN_HERE';
const mongoConnectionString = process.env.MONGO_CONNECTION_STRING ?? '';
const aidyn = new Aidyn({
Prefix: '%',
ConnectionString: mongoConnectionString, // Required for database features (MongoDB only)
BotToken: botToken,
Logging: 1 // Log commands. Use 0 for no logging, 2 for verbose (not recommended)
});
aidyn.start(commands);
console.log('Aidyn bot started with example command!');