Skip to content

This repo is a template for discord bots using discord.js and is written in ts, works with npm/pnpm and yarn.

License

Notifications You must be signed in to change notification settings

Dark-LYNN/DiscordBotTemplate

Discord.js Bot Template (TypeScript)

Maintainability Code Coverage Discord.js License: BSD-4-Clause

This is a template for a Discord.js bot written in TypeScript. It is designed to work with pnpm, npm, and yarn and includes a Prisma database integration. The template is licensed under BSD-4-Clause and comes with essential GitHub-related files.

Features

  • Written in TypeScript for type safety.
  • Supports pnpm, npm, and yarn for installation.
  • Uses kysely as the database ORM.
  • Pre-configured ESLint and Prettier for code quality.
  • Includes GitHub-related files (e.g., .gitignore, LICENSE, Issue Templates).
  • Organized structure with handlers for commands, events, interactions, and loops.
  • Custom logging with Winston.

Project Structure

.
├── database             # default location for database files.
├── scripts              # Package scripts (DB setup, linting, etcetera.)
├── src                  # Source code
│   ├── bot              # Core bot logic
│   ├── commands         # Command files
│   ├── database         # Database related files.
│   ├── events           # Event listeners
│   ├── middleware       # Middleware for permission checks
│   ├── tests            # Unit tests
│   ├── types            # TypeScript types
│   └── utils            # Utility functions
├── .eslintrc.cjs        # ESLint configuration
├── .prettierrc          # Prettier configuration
├── package.json         # Project metadata and dependencies
├── tsconfig.json        # TypeScript configuration
├── LICENSE              # BSD-4-Clause License
└── README.md            # Project documentation

Installation

  1. Clone the repository:

    git clone https://github.com/Dark-LYNN/DiscordBotTemplate.git
    cd discordbot-template
  2. Install dependencies with your preferred package manager:

    # Using pnpm
    pnpm install
    
    # Using npm
    npm install
    
    # Using yarn
    yarn install
  3. Set up the environment variables:

    • Create a .env file in the root directory.

    • Add your bot token and database URL:

      DISCORD_TOKEN=your-bot-token
      DISCORD_CLIENT_ID=your-bot-client-id
  4. Initialize the database:

    npm run db:migrate  # or pnpm db:migrate / yarn db:migrate

Usage

Development Mode

npm run dev  # or pnpm dev / yarn dev

This will start the bot using nodemon with ts-node to watch for file changes.

Production Mode

npm run build  # or pnpm build / yarn build
npm run start  # or pnpm start / yarn start

This will compile TypeScript to JavaScript and start the bot.

Scripts

  • lint – Run ESLint
  • lint:fix – Auto-fix linting issues
  • lint:spell – Run spell checking
  • lint:format – Format code with Prettier
  • release – Release a new version
  • test:all – Run all tests
  • db – Setup the database

Contributing

Contributions are welcome! Feel free to open an issue or pull request.

For info about contributing see our CONTRIBUTING.md.

License

This project is licensed under the BSD-4-Clause License. See the LICENSE file for details.

Acknowledgments

Thanks to all contributors and open-source projects that inspired this template.

About

This repo is a template for discord bots using discord.js and is written in ts, works with npm/pnpm and yarn.

Topics

Resources

License

Code of conduct

Contributing

Security policy

Stars

Watchers

Forks

Sponsor this project

Contributors 2

  •  
  •