Skip to content

Latest commit

 

History

History
52 lines (44 loc) · 3.18 KB

README.md

File metadata and controls

52 lines (44 loc) · 3.18 KB

TypeScript Discord Bot Template

discord.js License

This fork is a TypeScript rewrite of imconnorngl's JavaScript bot template.

Getting Started

Requirements

Create your bot

  • Go to the Discord Application Page.
  • Create a New Application.
  • Click Bot, Add Bot, then click Yes, do it.
  • Visit https://discord.com/oauth2/authorize?client_id=APP_ID&permissions=8&scope=bot%20applications.commands, replacing APP_ID with the Application ID from the app page, to add the bot to your server.
  • Copy your bot's Token and keep it for later.

Intents

  • Visit the same bot page where you got your token from.
  • Under Privileged Gateway Intents, enable Presence Intent, Server Members Intent, and Message Content Intent.
  • Click Save Changes at the bottom.

Setup

  • Create a local folder to store your bot's source code in.
  • Run git clone https://github.com/Krumbit/bot-template.git . in the folder directory.
  • Run pnpm install to install all required packages.
  • Rename the .env.example file to .env and paste your bot's token after the equals sign.
  • Read the next section for information on how to run the bot.

Running

TypeScript

These scripts use the ts-node CLI to run the TypeScript version of the bot, without transpiling to JavaScript. Use these only during development, as they are not as performant as the transpiled JavaScript version.

  • pnpm run dev
    • Runs the bot once
  • pnpm run dev:watch
    • Uses nodemon to automatically restart the bot after any file changes

JavaScript

These scripts manage the transpiled JavaScript version of the bot, ideally, in a production environment. These are more optimized and less resource intensive than the ts-node counterpart.

  • pnpm run build
    • Deletes the dist/ directory (if exists) and transpiles the TypeScript project to JavaScript
  • pnpm run start
    • Starts the JavaScript version of the bot from the dist/ directory
    • Requires pnpm run build to be ran previously
  • pnpm run build:start
    • Combination of the previous two scripts - transpiles to JavaScript and starts the dist bot automatically

Notes (important)

  • When changing types or adding new items to the config JSON files, update the interfaces in the src/utils/types directory. You can use an interface generator to simplify the process.
  • When updating command categories, be sure to update the Category enum in src/utils/structures/CommandHandler.ts as well. The value of the enum is the display name in the command help embeds.