{"id":18148219,"url":"https://github.com/the-best-codes/discraft-js","last_synced_at":"2025-06-12T02:35:10.253Z","repository":{"id":259999346,"uuid":"879099159","full_name":"The-Best-Codes/discraft-js","owner":"The-Best-Codes","description":"Discraft is a Discord bot framework with Vercel deployment, dev server, build optimization, and more","archived":false,"fork":false,"pushed_at":"2025-04-23T15:12:14.000Z","size":683,"stargazers_count":21,"open_issues_count":3,"forks_count":1,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-04-24T03:07:05.763Z","etag":null,"topics":["discord","discord-bot","discord-js","fast","framework","free","javascript","minimal","optimization","rollup","serverless","terser","vercel"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/The-Best-Codes.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":"SECURITY.md","support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2024-10-27T01:05:50.000Z","updated_at":"2025-04-23T15:12:19.000Z","dependencies_parsed_at":null,"dependency_job_id":"d9750d66-239e-49a7-bceb-fcabf60f9603","html_url":"https://github.com/The-Best-Codes/discraft-js","commit_stats":null,"previous_names":["the-best-codes/discraft-js"],"tags_count":94,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/The-Best-Codes%2Fdiscraft-js","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/The-Best-Codes%2Fdiscraft-js/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/The-Best-Codes%2Fdiscraft-js/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/The-Best-Codes%2Fdiscraft-js/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/The-Best-Codes","download_url":"https://codeload.github.com/The-Best-Codes/discraft-js/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250552076,"owners_count":21449164,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["discord","discord-bot","discord-js","fast","framework","free","javascript","minimal","optimization","rollup","serverless","terser","vercel"],"created_at":"2024-11-01T23:07:36.321Z","updated_at":"2025-06-12T02:35:10.246Z","avatar_url":"https://github.com/The-Best-Codes.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003cdiv align=\"center\"\u003e\n  \u003cimg alt=\"Discraft Logo\" src=\"https://github.com/user-attachments/assets/144fc363-a914-4e3a-851b-4f9744818930\" for=\"cover\" width=\"120\" /\u003e\n  \u003ch1\u003eDiscraft\u003c/h1\u003e\n\u003c/div\u003e\n\n[![npm version](https://img.shields.io/npm/v/discraft.svg)](https://www.npmjs.com/package/discraft)\n[![npm downloads](https://img.shields.io/npm/dm/discraft.svg)](https://www.npmjs.com/package/discraft)\n[![Discord Server](https://img.shields.io/discord/1170475897174896650)](https://discord.gg/dKeuR9yfBs)\n[![CodeQL](https://github.com/The-Best-Codes/discraft-js/actions/workflows/github-code-scanning/codeql/badge.svg)](https://github.com/The-Best-Codes/discraft-js/actions/workflows/github-code-scanning/codeql)\n[![Ask DeepWiki](https://deepwiki.com/badge.svg)](https://deepwiki.com/The-Best-Codes/discraft-js)\n\nDiscraft is a modern, developer-friendly framework for building Discord bots with ease.\nIt provides a robust CLI and a set of tools to streamline the development process, allowing you to focus on creating amazing bot experiences.\nThink of it as a \"batteries-included\" approach, letting you get started quickly and efficiently. It's like Next.js for Discord bots.\n\n\u003e **Note:** If you are viewing this documentation on npm, check out the [GitHub repository](https://github.com/The-Best-Codes/discraft-js) for more up-to-date documentation.\n\n## Table of Contents\n\n\u003e **Looking for instructions on how to deploy to Vercel?** Check out the [Vercel Deployment Guide](https://bestcodes.dev/blog/how-to-deploy-a-discord-bot-to-vercel).\n\n- [🚀 Getting Started](#-getting-started)\n  - [Installation](#installation)\n  - [Creating a New Project](#creating-a-new-project)\n  - [Running Your Bot](#running-your-bot)\n- [⚙️ Core Features](#️-core-features)\n  - [Command System](#command-system)\n  - [Event Handling](#event-handling)\n  - [Hot Reloading](#hot-reloading)\n  - [Flexible Build Options](#flexible-build-options)\n- [💻 CLI Reference](#-cli-reference)\n  - [`discraft init`](#discraft-init)\n  - [`discraft dev`](#discraft-dev)\n  - [`discraft build`](#discraft-build)\n  - [`discraft start`](#discraft-start)\n  - [`discraft vercel build`](#discraft-vercel-build)\n  - [`discraft exec build`](#discraft-exec-build)\n- [🚀 Deploying to Vercel](#-deploying-to-vercel)\n- [📁 Project Structure](#-project-structure)\n- [🛠️ Development](#️-development)\n  - [Dependencies](#dependencies)\n  - [Configuration](#configuration)\n  - [Commands and Events](#commands-and-events)\n- [🧪 Beta Releases](#-beta-releases)\n- [🤝 Contributing](#-contributing)\n- [📜 License](#-license)\n\n## 🚀 Getting Started\n\n### Installation\n\nYou can install Discraft locally in your project using `npm`, which is recommended for project-specific dependencies:\n\n```bash\nnpm install discraft --save-dev\n```\n\n\u003cdetails\u003e\n    \u003csummary\u003eAlternative Package Manager Commands\u003c/summary\u003e\n    \u003cp\u003e\n        If you prefer to use other package managers, here are the equivalent commands:\n        \u003cbr\u003e\n        \u003cb\u003epnpm:\u003c/b\u003e\n        \u003cpre\u003e\u003ccode\u003epnpm add discraft -D\u003c/code\u003e\u003c/pre\u003e\n        \u003cb\u003ebun:\u003c/b\u003e\n        \u003cpre\u003e\u003ccode\u003ebun add discraft --dev\u003c/code\u003e\u003c/pre\u003e\n        \u003cb\u003eyarn:\u003c/b\u003e\n        \u003cpre\u003e\u003ccode\u003eyarn add discraft -D\u003c/code\u003e\u003c/pre\u003e\n    \u003c/p\u003e\n\u003c/details\u003e\n\nAlternatively, you can install Discraft globally to use the CLI from any directory:\n\n```bash\nnpm install -g discraft\n```\n\nWhen installed globally, you can use the `discraft` command directly instead of `npx discraft`.\n\n### Creating a New Project\n\nTo get started quickly, use the `discraft init` command:\n\n```bash\nnpx discraft init\n```\n\nOr, if Discraft is installed globally:\n\n```bash\ndiscraft init\n```\n\nThis will guide you through creating a new Discraft bot project, asking for details such as the project directory, package manager, and template.\n\n**After initialization, you will need to copy the `.env.example` file to `.env` and then edit the `.env` file with your bot token and client ID.**\n\n```\n# From `Bot \u003e Token` | https://discord.com/developers/applications\nDISCORD_TOKEN=''\n# From `General Information \u003e App ID` | https://discord.com/developers/applications\nDISCORD_APP_ID=''\n```\n\nYou can also specify options directly:\n\n```bash\nnpx discraft init -d my-bot-dir -p bun -t ts # Initialize a project in 'my-bot-dir' using bun and the typescript template\n```\n\nSee the [CLI Reference](#-cli-reference) for all options.\n\n### Running Your Bot\n\nAfter creating your project, navigate into the project directory and use the following commands.\n\nTo start your bot in development mode:\n\n```bash\nnpx discraft dev\n```\n\n\u003cdetails\u003e\n    \u003csummary\u003eAlternative Package Manager Commands\u003c/summary\u003e\n    \u003cp\u003e\n        If you prefer to use other package managers, here are the equivalent commands:\n        \u003cbr\u003e\n        \u003cb\u003epnpm:\u003c/b\u003e\n        \u003cpre\u003e\u003ccode\u003epnpm discraft dev\u003c/code\u003e\u003c/pre\u003e\n        \u003cb\u003ebun:\u003c/b\u003e\n        \u003cpre\u003e\u003ccode\u003ebunx discraft dev\u003c/code\u003e\u003c/pre\u003e\n        \u003cb\u003eyarn:\u003c/b\u003e\n        \u003cpre\u003e\u003ccode\u003eyarn discraft dev\u003c/code\u003e\u003c/pre\u003e\n    \u003c/p\u003e\n\u003c/details\u003e\n\nOr, if Discraft is installed globally:\n\n```bash\ndiscraft dev\n```\n\nTo start your bot in production mode:\n\n```bash\nnpx discraft start\n```\n\n\u003cdetails\u003e\n    \u003csummary\u003eAlternative Package Manager Commands\u003c/summary\u003e\n    \u003cp\u003e\n        If you prefer to use other package managers, here are the equivalent commands:\n        \u003cbr\u003e\n        \u003cb\u003epnpm:\u003c/b\u003e\n        \u003cpre\u003e\u003ccode\u003epnpm discraft start\u003c/code\u003e\u003c/pre\u003e\n        \u003cb\u003ebun:\u003c/b\u003e\n        \u003cpre\u003e\u003ccode\u003ebunx discraft start\u003c/code\u003e\u003c/pre\u003e\n          \u003cb\u003eyarn:\u003c/b\u003e\n        \u003cpre\u003e\u003ccode\u003eyarn discraft start\u003c/code\u003e\u003c/pre\u003e\n    \u003c/p\u003e\n\u003c/details\u003e\n\nOr, if Discraft is installed globally:\n\n```bash\ndiscraft start\n```\n\n## ⚙️ Core Features\n\nDiscraft offers a range of features designed to make Discord bot development a breeze.\n\n### Command System\n\nDiscraft uses the Discord.js API to create robust slash commands, as well as message and user context menu commands. Place your command files in the `commands` directory, and Discraft will automatically register them with Discord on bot startup.\n\nSee [examples of commands here](https://github.com/The-Best-Codes/discraft-js/tree/main/templates/ts/commands).\n\n### Event Handling\n\nDiscraft simplifies registering event handlers. Place your event files in the `events` directory, and Discraft will register them when the bot starts.\n\nExample event handler (`events/ready.ts`, which will be registered when the bot starts):\n\n```typescript\nimport { ActivityType, Client, Events } from \"discord.js\";\nimport { logger } from \"../utils/logger\";\n\nexport default {\n  event: Events.ClientReady,\n  handler: (client: Client) =\u003e {\n    if (!client.user) {\n      logger.error(\"Client user is not set.\");\n      return;\n    }\n    client.user.setPresence({\n      activities: [\n        {\n          name: \"Discraft\",\n          // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n          // @ts-ignore Discord.js does not have this property, but it is valid\n          state: \"Created with Discraft\",\n          type: ActivityType.Custom,\n        },\n      ],\n      status: \"online\",\n    });\n    logger.success(\"Client logged in.\");\n  },\n};\n```\n\nSee [examples of more events here](https://github.com/The-Best-Codes/discraft-js/tree/main/templates/ts/events).\n\n### Hot Reloading\n\nDuring development, Discraft supports hot reloading, meaning that your changes to command and event files will automatically restart your bot with the changes reflected. This allows for a more efficient and streamlined development process.\n\n### Flexible Build Options\n\nDiscraft allows you to choose your preferred builder when building and running your application in development mode.\n\n- `esbuild`: A fast and efficient JavaScript bundler.\n- `bun`: A fast all-in-one toolkit for JavaScript and Typescript\n\n## 💻 CLI Reference\n\nDiscraft provides a set of powerful CLI commands to manage your bot development.\n\n### `discraft init`\n\nInitializes a new Discraft project.\n\n**Options:**\n\n- `-d, --dir \u003cdirectory\u003e`: Specify the project directory (defaults to current directory).\n- `-p, --package-manager \u003cpm\u003e`: Package manager to use (npm, yarn, pnpm, bun, or none).\n- `--skip-install`: Skip dependency installation.\n- `-t, --template \u003ctemplate\u003e`: Template to use (js, ts, or vercel-ts-ai). Defaults to prompt.\n\n**Example:**\n\n```bash\nnpx discraft init -d my-bot -p bun --skip-install -t ts\n```\n\nOr, if Discraft is installed globally:\n\n```bash\ndiscraft init -d my-bot -p bun --skip-install -t ts\n```\n\n### `discraft dev`\n\nStarts the bot in development mode with hot reloading.\n\n**Options:**\n\n- `-b, --builder \u003cbuilder\u003e`: Specify the builder to use (esbuild or bun). Defaults to auto-detect.\n- `-r, --runner \u003crunner\u003e`: Specify the runner to use (node or bun). Defaults to auto-detect.\n- `-c, --clear-console`: Clear the console on each rebuild.\n\n**Example:**\n\n```bash\nnpx discraft dev -b esbuild -r bun -c\n```\n\nOr, if Discraft is installed globally:\n\n```bash\ndiscraft dev -b esbuild -r bun -c\n```\n\n### `discraft build`\n\nBuilds the bot for production.\n\n**Options:**\n\n- `-b, --builder \u003cbuilder\u003e`: Specify the builder to use (esbuild or bun). Defaults to auto-detect.\n\n**Example:**\n\n```bash\nnpx discraft build -b bun\n```\n\nOr, if Discraft is installed globally:\n\n```bash\ndiscraft build -b bun\n```\n\n### `discraft start`\n\nStarts the bot in production mode.\n\n**Options:**\n\n- `-r, --runner \u003crunner\u003e`: Specify the runner to use (node or bun). Defaults to auto-detect.\n\n**Example:**\n\n```bash\nnpx discraft start -r node\n```\n\nOr, if Discraft is installed globally:\n\n```bash\ndiscraft start -r node\n```\n\n### `discraft vercel build`\n\nBuilds the bot for deployment on Vercel. This command is a subcommand of `discraft vercel`.\n\n**Options:**\n\n- `-b, --builder \u003cbuilder\u003e`: Specify the builder to use (esbuild or bun). Defaults to auto-detect.\n\n**Example:**\n\n```bash\nnpx discraft vercel build -b bun\n```\n\nOr, if Discraft is installed globally:\n\n```bash\ndiscraft vercel build -b bun\n```\n\n### `discraft exec build`\n\nBuilds a standalone executable of your bot. This command is a subcommand of `discraft exec`.\n\n**Important notes:**\n\n- You must run `discraft build` before running `discraft exec build`.\n- This command only works with the JavaScript and TypeScript templates (not the Vercel template).\n- The `.env` file should be in the same directory as the executable or the bot won't start.\n\n**Options:**\n\n- `--target \u003ctarget\u003e`: Target platform for executable.\n  Supported targets:\n  - `linux-x64`\n  - `linux-arm64`\n  - `windows-x64`\n  - `darwin-x64`\n  - `darwin-arm64`\n- `--entry \u003centry\u003e`: Custom entry point (defaults to `dist/index.js`).\n- `--outfile \u003coutfile\u003e`: Output file name (defaults to `dist/discraft-bot`).\n\n**Targets:**\n\n| Target       | OS      | Architecture |\n| ------------ | ------- | ------------ |\n| linux-x64    | Linux   | x64          |\n| linux-arm64  | Linux   | arm64        |\n| windows-x64  | Windows | x64          |\n| darwin-x64   | macOS   | x64          |\n| darwin-arm64 | macOS   | arm64        |\n\nYou can find more information about targets in the [Bun documentation](https://bun.sh/docs/bundler/executables#cross-compile-to-other-platforms).\n\n**Example:**\n\n```bash\nnpx discraft exec build --target linux-x64\n```\n\nOr, if Discraft is installed globally:\n\n```bash\ndiscraft exec build --target linux-x64\n```\n\n## 🚀 Deploying to Vercel\n\n**Check out the [Vercel Deployment Guide](https://bestcodes.dev/blog/how-to-deploy-a-discord-bot-to-vercel) for a more detailed, step-by-step guide.**\n\nTo deploy your Discraft bot to Vercel, follow these steps:\n\n1. **Create a Vercel Project:** If you haven't already, create a new project in your Vercel dashboard. You can import your project from GitHub, GitLab or Bitbucket.\n2. **Set Environment Variables:** In your Vercel project settings, go to \"Environment Variables\" and add the following variables:\n   - `DISCORD_TOKEN`: Your Discord bot's token.\n   - `DISCORD_APP_ID`: Your Discord application's ID.\n   - **For AI templates:**\n     - `GOOGLE_AI_API_KEY`: Your Google AI API key.\n     - `GOOGLE_AI_MODEL`: The Google AI model you wish to use (e.g., `gemini-2.0-flash-exp`).\n       You can find the project settings [here](https://vercel.com/dashboard).\n3. **Run a Discraft Vercel Build**: In your project directory, run `npm run vercel-build` or `discraft vercel build` to create the API routes and files for your bot. This command prepares your bot for serverless deployment by generating the necessary API routes.\n   \u003cdetails\u003e\n        \u003csummary\u003eAlternative Package Manager Commands\u003c/summary\u003e\n        \u003cp\u003e\n            If you prefer to use other package managers, here are the equivalent commands:\n            \u003cbr\u003e\n             \u003cb\u003epnpm:\u003c/b\u003e\n                \u003cpre\u003e\u003ccode\u003epnpm discraft vercel build\u003c/code\u003e\u003c/pre\u003e\n             \u003cb\u003ebun:\u003c/b\u003e\n                \u003cpre\u003e\u003ccode\u003ebunx discraft vercel build\u003c/code\u003e\u003c/pre\u003e\n              \u003cb\u003eyarn:\u003c/b\u003e\n                \u003cpre\u003e\u003ccode\u003eyarn discraft vercel build\u003c/code\u003e\u003c/pre\u003e\n        \u003c/p\u003e\n    \u003c/details\u003e\n4. **Deploy:** You can deploy your bot to Vercel by running `npm run deploy` or using the `vercel` CLI. If using the CLI, you can run `vercel` and select the project you created. If you imported your project from a git repo, it should automatically deploy on commits. You can now set your bot's interactions endpoint to the `https://\u003cyour-project\u003e.vercel.app/api` url.\n   - To setup the interactions endpoint, please see the 'Discord Bot Setup' section of the Vercel + TypeScript + Google AI template [README](https://github.com/The-Best-Codes/discraft-js/blob/main/templates/vercel-ts-ai/README.md).\n\n## 📁 Project Structure\n\nA typical Discraft project is structured as follows:\n\n```\nmy-discraft-bot/\n├── .discraft/            # Internal Discraft files (auto-generated)\n├── clients/             # Discord.js client setup\n│   └── discord.ts       # Discord.js client configuration\n├── commands/            # Your bot's command files\n│   ├── ping.ts           # Example ping command\n│   └── ...             # Other commands\n├── events/              # Event handlers\n│   ├── error.ts          # Error handling\n│   ├── messageCreate.ts  # Example message handler\n│   └── ready.ts          # Client ready handler\n├── utils/               # Utility functions\n│   └── logger.ts        # Logging configuration\n├── index.ts             # Main entry point for the bot\n├── package.json         # Project dependencies and scripts\n├── tsconfig.json        # TypeScript configuration\n└── .env                 # Environment variables (e.g., bot token)\n```\n\n## 🛠️ Development\n\n### Dependencies\n\nDiscraft relies on the following key dependencies:\n\n- `discord.js`: A powerful JavaScript library for interacting with the Discord API.\n- `commander`: A library for building command-line interfaces.\n- `consola`: A modern console logger.\n- `esbuild` or `bun`: Fast JavaScript bundlers.\n- `dotenv`: To load environment variables.\n- `chokidar`: File watcher.\n- `fs-extra`: Extra file system methods.\n- `glob`: File globbing.\n- `clack`: Interactive CLI prompts.\n- `kleur`: Colorful console output.\n  - All of these are included as dependencies to discraft itself.\n\n### Configuration\n\nStore your bot's token and client ID in a `.env` file at the root of your project:\n\n```\nDISCORD_TOKEN=your_bot_token_here\nDISCORD_APP_ID=your_client_id_here\n```\n\n### Commands and Events\n\n- Command files are located in the `commands` directory. They export an object with `data` and `execute` properties.\n- Event files are located in the `events` directory. They export an object with `event` and `handler` properties.\n\n## 🧪 Beta Releases\n\nBeta versions are available for testing new features. To install the latest beta:\n\n```bash\nnpm install discraft@beta\n```\n\n## 🤝 Contributing\n\nContributions are welcome! Please visit the [GitHub repository](https://github.com/The-Best-Codes/discraft-js) to report issues or submit pull requests.\n\n## 📜 License\n\nThis project is licensed under the [MIT License](LICENSE).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fthe-best-codes%2Fdiscraft-js","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fthe-best-codes%2Fdiscraft-js","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fthe-best-codes%2Fdiscraft-js/lists"}