Skip to content

sebferrer/discord-bot-ts-template

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Discord Bot Template in TypeScript

This is a minimal architecture for building a discord bot in TypeScript, based on discord.js, injection.js and RxJS.

Examples

This template provides :

  • A message sending in a text channel.
  • A periodic sending of message in a text channel via Cron.
  • A command builder with two examples (/help, /faq), and an Interaction listener.
  • A command registerer.

Getting Started

Define your Token, Client ID and Guild ID

Create an .env file at the root of your project and define your Discord bot token, Client ID and Guild ID in a variable as following:

TOKEN="Your_token_here"
CLIENT_ID="Your_client_id_here"
GUILD_ID="Your_guild_id_here"

Define your channels

The channel IDs are defined in src/infra/channels-static.json

[
    {
        "key": "custom_key",
        "id": "channel_id"
    }
]

Install dependencies

npm install

Build

npm run build

Deploy commands

npm run deploy-commands

Run

npm start

Deploy commands & Run with vite-node (dev)

npm run deploy-commands:dev
npm start:dev

References

  • discord.js: Node.js module to interact with the Discord API.
  • vite-note: Vite as Node runtime.
  • TypeScript: JavaScript with syntax for types.
  • RxJS: Reactive Extensions Library for JavaScript.
  • injection-js: Dependency injection library for JavaScript and TypeScript.