JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 788
  • Score
    100M100P100Q92876F
  • License MIT

Discord.js bot builder. Supports Ts and Js.

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

  1. Build your library:
npm run build
  1. Publish to NPM:
npm publish

๐Ÿค Contributing

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/AmazingFeature)
  3. Commit your changes (git commit -m 'Add some AmazingFeature')
  4. Push to the branch (git push origin feature/AmazingFeature)
  5. 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


Made with โค๏ธ by [Rashi aka Malzahir]