Skip to content

TeloiDev/typescript-discord.js-template

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

TypeScript discord.js template

This repo was made so everyone can easily start their discord.js bots with typescript!

Getting Started

In order to start with this template first you need to install this repo with git clone typescript-discord.js-template or just download it through GitHub.

Once you're done remove every .example from files' and directories' names and run npm install.


Customizing

The purpose of TypeScript is to strongly type your code so you need to set up everything in types/ directory.

Comamand

This is the default state of Command interface. You can add any other properity that you need.

import { Message } from "discord.js";

// If you need any other properities for a command add them here
declare module "discord.js" {
  export interface Command {
    name: string;
    description: string;
    isTypescriptFun: boolean;
    expectedArgsAmount: number;
    // etc.
    run: (message: Message, args: string[]) => void;
  }
}

Client

Same aplies to Client interface. This is it's default state and here's how you can change it to your needs.

import { Collection } from "discord.js";

// In case you need any other collectors add them here
declare module "discord.js" {
  export interface Client {
    commands: Collection<unknown, Command>;
    aliases: Collection<unknown, any>; // Using any should be a final decission and you shouldn't use it unless it's necessary
  }
}

.env and basic setup

I don't think I have to explain this. Just modify it so you can actually use the bot

env:

DISCORD_TOKEN=your discord bot token

You can find your bot's prefix in messageCreate.ts file.


Adding new Commands and Events

Events

Remember to name your event files same as the actual event's name.

Example: if an event is called "messageDelete" name your file "messageDelete.ts" etc.

Command

Pretty straightforward. Just make sure that every command has a unique name.


Contributing

As always every contributions is welcome. For major changes open an issue first and describe what you want to change

About

A simple startup codebase for a discord.js bot built with typescript

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published