Package Exports
- malzahir
- malzahir/dist/index.js
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (malzahir) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
๐ Rashi Discord
A powerful, feature-rich Discord bot framework built with TypeScript. It provides a complete toolkit for modern bot development, making it easy to build, scale, and maintain production-ready bots.
โจ Key Features
- ๐ง TypeScript First โ Full type safety, IntelliSense, and modern development practices
- ๐๏ธ VerseDB Integration โ Lightweight database system with support for JSON, YAML, and MongoDB
- ๐ Automatic Loading โ Seamless auto-registration of events and commands
- ๐ Built-in Encryption โ AES-secured storage for sensitive data
- ๐ Hot Reloading โ File watcher for rapid development
- ๐ก๏ธ Crash Protection โ Automatic error handling and reporting
- ๐จ Advanced Logging โ Color-coded logs with timestamps and categories
- ๐ฆ Flexible Package Manager Support โ Works with both Yarn and NPM
- ๐ Bot Analytics โ Integrated statistics and activity tracking
- ๐งฉ Middleware System โ Guard commands with ownerOnly, cooldown, requirePermissions, nsfwOnly, devOnly, etc.
- ๐ต Music Support โ Lavalink/YouTube/Spotify integrations
- โฐ Task Scheduler โ Interval, CRON, and delayed jobs built-in
๐ ๏ธ Installation
npm install rashi-discord
# or
yarn add rashi-discord๐ Quick Start
Advanced Configuration
// src/index.ts - Main bot entry point
import { Client, GatewayIntentBits } from "discord.js";
import { starter } from "rashi-discord";
import dotenv from "dotenv";
import path from "path";
dotenv.config();
const client = new Client({
intents: [
GatewayIntentBits.Guilds,
GatewayIntentBits.GuildMessages,
GatewayIntentBits.MessageContent,
GatewayIntentBits.GuildMembers,
GatewayIntentBits.GuildVoiceStates,
],
});
const botConfig = {
bot: {
token: process.env.DISCORD_TOKEN!,
ownerId: process.env.BOT_OWNER_ID!,
clientId: process.env.CLIENT_ID!,
devGuildId: process.env.DEV_GUILD_ID,
},
prefix: { path: path.join(__dirname, "commands", "general"), prefix: "!" },
slash: { path: path.join(__dirname, "commands", "slash") },
nonprefix: { path: path.join(__dirname, "commands", "nonprefix") },
events: { path: path.join(__dirname, "events") },
// โฌ
๏ธ dopisane
poruEvents: { path: path.join(__dirname, "poru-events") },
terminal: true,
Status: {
status: "online" as const,
activities: [
"Obsลugujฤ {users} uลผytkownikรณw ๐ฅ",
"Na {servers} serwerach ๐",
"Mam {commands} komend โก",
"Uลผyto mnie {used} razy ๐",
"Kocham was โค๏ธ",
],
time: 30000,
},
music: {
enabled: true,
nodes: [
{
name: "RY4N",
host: "vip.visionhost.cloud",
port: 7023,
password: "youshallnotpass",
secure: false,
},
],
defaultVolume: 80,
defaultPlatform: "ytsearch",
autoLeave: true,
reconnectTries: 5,
reconnectInterval: 5000,
requestTimeout: 10000,
resume: true,
resumeKey: "rashi-music",
resumeTimeout: 60_000,
autoPlay: true,
queueLimit: 200,
trackMaxLength: 0,
},
database: {
type: (process.env.DB_TYPE as "mongodb" | "json" | "yaml") || "mongodb",
connectionString: process.env.MONGO_URL,
path: "./database",
encryption: false,
encryptionKey: process.env.DB_KEY || undefined,
},
};
starter(client, botConfig).then(() => {
console.log("โ
Bot started!");
});
๐ Project Structure
your-bot/
โโโ commands/
โ โโโ general/
โ โ โโโ ping.ts
โ โ โโโ info.ts
โ โโโ slash/
โ โโโ help.ts
โ โโโ stats.ts
โโโ events/
โ โโโ ready.ts
โ โโโ messageCreate.ts
โโโ index.ts
โโโ package.json๐ฏ Command Examples
Prefix Command
// commands/general/ping.ts
// src/commands/general/ping.ts - Example prefix command
import { Message } from 'discord.js';
import { Command } from 'rashi-discord';
const pingCommand: Command = {
name: 'ping',
description: 'Check bot latency and response time',
aliases: ['p', 'latency'],
cooldown: 5, // 5 seconds cooldown
async execute(message: Message, args: string[]) {
const start = Date.now();
const reply = await message.reply('๐ Calculating ping...');
const latency = Date.now() - start;
const apiLatency = Math.round(message.client.ws.ping);
const embed = {
title: '๐ Pong!',
fields: [
{
name: '๐ Bot Latency',
value: `\`${latency}ms\``,
inline: true
},
{
name: '๐ API Latency',
value: `\`${apiLatency}ms\``,
inline: true
},
{
name: 'โฑ๏ธ Status',
value: latency < 100 ? '๐ข Excellent' : latency < 200 ? '๐ก Good' : '๐ด Slow',
inline: true
}
],
color: latency < 100 ? 0x00FF00 : latency < 200 ? 0xFFFF00 : 0xFF0000,
timestamp: new Date().toISOString(),
footer: {
text: `Requested by ${message.author.username}`,
icon_url: message.author.displayAvatarURL()
}
};
await reply.edit({ content: '', embeds: [embed] });
}
};
export default pingCommand;Slash Command
// commands/slash/info.ts
// commands/slash/slash.ts - FIXED
import { SlashCommand } from 'rashi-discord';
import { SlashCommandBuilder, CommandInteraction } from 'discord.js';
const slashCommand: SlashCommand = {
data: new SlashCommandBuilder()
.setName('info')
.setDescription('Display bot information'),
async execute(interaction: CommandInteraction): Promise<void> {
const embed = {
title: 'Bot Information',
description: 'Bot created with Rashi Discord',
color: 0x5865F2,
fields: [
{
name: 'Statistics',
value: `Servers: ${interaction.client.guilds.cache.size}\nUsers: ${interaction.client.users.cache.size}`
}
],
timestamp: new Date().toISOString()
};
await interaction.reply({ embeds: [embed] });
}
};
export default slashCommand;๐ Event Example
// events/ready.ts
import { Event } from 'rashi-discord';
import { Client } from 'discord.js';
const readyEvent: Event = {
name: 'ready',
once: true,
execute: async (client: Client) => {
console.log(`โ
Bot ${client.user?.tag} jest gotowy!`);
// Set bot status
client.user?.setActivity('๐ฎ Rashi Discord', { type: 'PLAYING' });
}
};
export default readyEvent;โฐ Task Scheduler
You can schedule jobs directly from commands or events with simple syntax:
client.scheduler.once("reminder-123", "5m", () => {
console.log("โฐ Reminder after 5 minutes!");
});or
client.scheduler.every("stats-log", "10m", () => {
client.logger.info(
`๐ Guilds=${client.guilds.cache.size}, Users=${client.users.cache.size}`
);
});
or
client.scheduler.cron("daily-announcement", "0 12 * * *", () => {
const channel = client.channels.cache.get("1234567890");
if (channel?.isTextBased()) {
channel.send("โ๏ธ Daily announcement: Have a great day!");
}
});๐งฉ Middleware
Middlewares run before executing a command and can block or modify execution. They are reusable plugins (like Express middlewares).
Permissions Middleware
import { requirePermissions } from "rashi-discord";
const echo: SlashCommand = {
data: new SlashCommandBuilder()
.setName("echo")
.setDescription("Echo your input")
.addStringOption(opt =>
opt.setName("text").setDescription("Text to echo").setRequired(true)
),
middlewares: [requirePermissions(["ManageMessages"])],
async execute(interaction) {
const text = interaction.options.getString("text", true);
await interaction.reply(`๐ ${text}`);
},
};Built-in middlewares
ownerOnly() โ restrict to bot owner
devOnly() โ restrict to developers
cooldown(ms) โ add cooldown to commands
requirePermissions([...]) โ check user permissions
nsfwOnly() โ restrict to NSFW channels
argsRequired(min) โ enforce args
requireRole("Admin") / requireRoles(["Mod", "Helper"])๐๏ธ Database Usage
MongoDB
// MongoDB automatically connected if configured
const user = await bot.database?.findOne('users', { id: '123456789' });
await bot.database?.insertOne('users', {
id: '123456789',
username: 'JohnDoe',
coins: 100
});JSON/YAML (VerseDB)
// Works the same way as MongoDB
const guild = await bot.database?.findOne('guilds', { id: message.guild.id });
await bot.database?.updateOne('guilds',
{ id: message.guild.id },
{ prefix: '?' }
);๐ Bot Statistics
Access real-time bot statistics:
console.log(bot.stats);
// Output:
// {
// commandsUsed: 42,
// slashCommandsUsed: 18,
// eventsTriggered: 156,
// uptime: 3600
// }๐จ Advanced Logging
import { Logger } from 'rashi-discord';
const logger = new Logger({
level: 'debug',
colorized: true,
saveToFile: true,
filePath: './logs/custom.log'
});
logger.info('โ
Bot started successfully');
logger.warn('โ ๏ธ High memory usage detected');
logger.error('โ Database connection failed');๐ง Configuration Options
| Option | Type | Default | Description |
|---|---|---|---|
token |
string |
required | Discord bot token |
prefix |
string |
'!' |
Command prefix |
database |
DatabaseConfig |
undefined |
Database configuration |
logging |
LoggingConfig |
{ level: 'info' } |
Logging settings |
antiCrash |
boolean |
true |
Enable anti-crash system |
hotReload |
boolean |
false |
Enable hot reloading |
scheduler |
TaskScheduler |
built-in |
Run tasks with intervals/CRON |
Database Configuration
interface DatabaseConfig {
type: 'mongodb' | 'json' | 'yaml';
connectionString?: string; // For MongoDB
path?: string; // For JSON/YAML files
encryption?: boolean;
encryptionKey?: string;
}๐ฅ Hot Reloading
Enable hot reloading for development:
const bot = new BotStarter({
token: 'YOUR_BOT_TOKEN',
hotReload: true // Automatically reloads commands and events on file changes
});๐ก๏ธ Anti-Crash System
Built-in protection against crashes:
- Handles unhandled promise rejections
- Catches uncaught exceptions
- Logs Discord.js errors
- Keeps your bot running 24/7
๐ฆ Publishing to NPM
- Build your library:
npm run build- Publish to NPM:
npm publish๐ค Contributing
- Fork the repository
- Create your feature branch (
git checkout -b feature/AmazingFeature) - Commit your changes (
git commit -m 'Add some AmazingFeature') - Push to the branch (
git push origin feature/AmazingFeature) - Open a Pull Request
๐ License
This project is licensed under the MIT License - see the LICENSE file for details.
๐ฏ Examples
Check out the examples folder for complete bot implementations using Rashi Discord.
๐ Support
- ๐ Documentation
- ๐ Report Bugs
- ๐ฌ Discord Server
Made with โค๏ธ by [Rashi aka Malzahir]