npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

discraft

v1.5.5

Published

Like Next.js, but for Discord bots

Downloads

3,008

Readme

Publish to npm CodeQL Dependabot Updates Discord Server npm version npm downloads

Discraft

Discraft is a powerful framework for creating Discord bots, offering a robust CLI and a set of tools to streamline the development process. Think of it like Next.js but for Discord bots.

Features

  • Command Caching: Built-in LRU cache system for commands with configurable TTL and memory limits
  • Multi-step Commands: Support for commands that require follow-up responses or editing
  • Robust CLI: Comprehensive command-line interface for development and deployment
  • Modern Build System: Advanced bundling with Rollup, Babel transformations, and Terser minification
  • Hot Reload: Automatic server restart on code changes during development
  • Optimized Production Builds: Aggressive minification for production with preserved functionality

Installation

You can install Discraft via npm:

npm install discraft --save-dev # Use this to install Discraft in the current project
npm install discraft -g # May require sudo, globally installs Discraft so you can use it from anywhere

# For beta releases
npm install discraft@beta # Install the latest beta version

Usage

Discraft provides a CLI interface. You can use Discraft like this:

npx discraft [command]
# or
discraft [command]

CLI Commands

  • discraft init: Initialize a new Discraft project.
  • discraft dev: Start the development server.
  • discraft build: Build the project for production.
  • discraft start: Start the production server.
  • discraft test token: Test your bot token and client ID.
  • discraft add command: Create a new command file.
  • discraft add event: Create a new event handler file.
  • discraft help: Display available commands and help options.

Project Structure

The project is organized into several directories:

  • src/commands: Contains command files for the bot
  • src/events: Contains event handlers for Discord events
  • src/config: Configuration files for bot settings
  • src/services: Service integrations (Discord.js client setup)
  • src/utils: Utility functions including logging and caching

Auto-generated

  • src/discraft: Core framework functionality, auto-generated by Discraft

Build Output Structure

When built for production, the project is rolled up into a single file called bundle.js. This file is the entry point for the bot and includes all necessary dependencies and configurations. It's easy to deploy to production and is optimized for performance.

Development

To start the development server:

discraft dev

The development server provides:

  • Hot reloading of command and event files
  • Detailed logging with debug information
  • Automatic error handling and recovery

Dependencies

Key production dependencies (v1.5.4):

  • discord.js: ^14.16.3
  • @babel/core: ^7.26.0
  • @rollup/plugin-babel: ^6.0.4
  • commander: ^12.1.0
  • dotenv: ^16.4.5
  • rollup: ^4.27.3
  • terser: ^5.36.0

Development tools:

  • eslint: ^9.15.0
  • Various ESLint plugins for code quality

Command Caching

Discraft includes a powerful command caching system to improve performance and reduce API calls:

import { SlashCommandBuilder } from "discord.js";
import { commandCache } from "../utils/commandCache.js";

// Set command-specific cache settings
commandCache.setCommandSettings("ping", {
  ttl: 5000, // Cache ping results for 5 seconds
});

export default {
  data: new SlashCommandBuilder()
    .setName("ping")
    .setDescription("Replies with Pong"),
  cacheable: true,
  async execute(interaction) {
    const response = `Pong! Latency: ${Math.round(
      interaction.client.ws.ping
    )}ms`;
    await interaction.reply(response);
    return { content: response }; // Return in a format that can be used by interaction.reply()
  },
};

The caching system supports both simple responses and multi-step interactions. For multi-step commands, you can return an array of steps:

export default {
  data: new SlashCommandBuilder()
    .setName("complex-status")
    .setDescription("Complex status check with updates"),
  cacheable: true,
  execute: async (interaction) => {
    return {
      steps: [
        { content: "Initial response..." },
        { type: "edit", content: "Updated status..." },
        { type: "followUp", content: "Additional info..." },
      ],
    };
  },
};

The cache system automatically handles:

  • Storing command results based on command name and options
  • Multi-step responses with edits and follow-ups
  • Command-specific TTL (Time To Live) settings
  • LRU (Least Recently Used) eviction strategy
  • Memory management

Setup

  1. Install dependencies:

    npm install
  2. Create a .env file with your bot token:

    BOT_TOKEN=your_bot_token_here
    CLIENT_ID=your_client_id_here
  3. Start development:

    discraft dev

Beta Releases

Beta versions are available for testing new features. To install the latest beta:

npm install discraft@beta

Contributing

Contributions are welcome! Please visit the GitHub repository to report issues or submit pull requests.

License

This project is licensed under the GNU General Public License 3.0.