Skip to content
/ discord-bot-starter Public template
generated from threeal/nodejs-starter

A minimalist template for starting a new Discord bot project

License

Notifications You must be signed in to change notification settings

threeal/discord-bot-starter

Repository files navigation

Discord Bot Starter

A minimalist template for starting a new Discord bot project.

This template provides a basic Discord bot project containing a sample bot application that supports slash commands. The project is written in TypeScript and utilizes the Sapphire framework to help create the bot application. To simplify deployment, this template includes support for building a Docker image of the bot project.

Key Features

  • Minimal Discord bot project written in TypeScript with ESM support.
  • Uses Sapphire as the framework for creating the Discord bot application.
  • Supports building the Discord bot application as a Docker image.
  • Uses pnpm as the package manager.
  • Supports formatting with Prettier and linting with ESLint.
  • Fixes formatting and linting during pre-commit hooks using Lefthook.
  • Preconfigured workflows for Dependabot and GitHub Actions.

Usage

This guide explains how to use this template to start a new Discord bot project, from creation to deployment.

Create a New Project

Follow this link to create a new project based on this template. For more information about creating a repository from a template on GitHub, refer to this documentation.

Alternatively, you can clone this repository locally to begin using this template.

Choose a License

By default, this template is unlicensed. Before modifying this template, replace the LICENSE file with the license to be used by the new project. For more information about licensing a repository, refer to this documentation.

Alternatively, you can remove the LICENSE file or leave it as-is to keep the new project unlicensed.

Update the Readme File

Update the content of this README.md file with a description of the new project. For more information on adding READMEs to a project, refer to this documentation.

Set Up the Tools

This template uses pnpm as the package manager. If pnpm is not installed, follow this guide to install it. Then, install the project dependencies with:

pnpm install

For more information on pnpm, including adding dependencies or running tools, refer to this documentation.

Set Up the Bot Application

Before developing the bot application, ensure that you have set up a bot application and obtained a token to be used to access the bot. If not, refer to this documentation for setting up a new bot application and getting the access token.

After obtaining the access token, export it as a DISCORD_TOKEN variable in your shell environment.

Develop the Bot Application

Develop the bot application by modifying the files under the src directory according to the project requirements. For more detailed guidance on developing the bot application, refer to the Sapphire documentation and the TypeScript documentation.

After you're done, run the bot application using the following command:

pnpm start

Deploy the Bot Application

The bot application can simply be deployed by running the pnpm start command on a specific machine. Alternatively, the bot application can also be deployed as a Docker container, allowing it to run as a service while keeping the application contained in an isolated environment.

To do this, first, build the bot application into a Docker image using the following command:

docker build -t discord-bot .

Then run the Docker image as a service using the following command:

docker run -dt -e DISCORD_TOKEN=$DISCORD_TOKEN discord-bot

Refer to this documentation for more information on using Docker for managing containerized applications.