Skip to content
/ discordbot Public template

A simple discord bot with custom handler made in discord.js v14

License

Notifications You must be signed in to change notification settings

EvolutionX-10/discordbot

Repository files navigation

Discord bot written in TypeScript


discord.js

About the project

This project is not intended to be a fully-functional bot, but rather a simple handler for handling of commands and events. I've seen a lot of people finding it hard to make their own handlers in TypeScript and ending up using any everywhere. This place can be a good start for you to begin your journey of making a bot in TypeScript without depending on other dedicated handlers. Custom handlers have this advantage that its your own handler, you can add whatever feature you like and whatever you want.

Features

  • Written in TypeScript 😋
  • Uses v14.15 😎
  • Fully ESM based 😍
  • Minimal dependencies ⚡
  • Automated Registering/Updating/Deleting/Syncing of Application Commands 😮
  • Default commands 😄
    • Chat Input (Slash) Commands [ping, eval, paginate, survey]
    • User Commands [pong]
    • Message Commands [Save]
    • Legacy Commands [say, paginate, survey]
  • Supports Message Commands, Chat Input Commands, ContextMenu Commands, and more! 😜
  • Type safe, simple, and easy to understand 👍
  • Valid and Robust Autocompletions in your IDE for commands and listeners 😲
  • Extended Client with useful features 🤩
  • Colorful and detailed logging 💡
  • Paginator Class for easy pagination using embeds, buttons, and select menus! 😉
  • Resolver Class for easy resolving of multi mentions in chat input command option! 😳
  • Prompt Class if you want to ask series of questions and have message content intent 🤗

Before you begin

This guide assumes you have solid understanding of JavaScript and at least basic understanding of TypeScript. If you don't, I recommend you start with the JavaScript guide and TypeScript book.

Getting Started

Click on Use this template button and it will generate a new repository based on this repository in your account. Once done, you may clone your repository locally using git1.
You also need to have a Discord Bot application created. If you haven't done it yet, you can do it by following the guide here.

Dev Setup

Now you can proceed to install dependencies.
After that, we will compile our TypeScript code to JavaScript

Note This project uses bun to manage dependencies. If you don't have bun installed, you can read here on how to install it.

bun install

Setting token

  1. Rename .env.example to .env
  2. Add your token to the .env file in this format
DISCORD_TOKEN=<your-token-without-braces>

Starting the bot

Now we can start the bot using bun run dev script.

bun run dev

Production Setup

To run in production environment, we use Docker. You can read more about it here.

Building the image

docker build -t discordbot .

Running the image

docker run -d --name discordbot -e DISCORD_TOKEN=<your-token-without-braces> discordbot

Commands and Listeners

Commands

Example

import { CommandType } from '#lib/enums';
import { Command } from '#lib/structures';

export default new Command({
	type: CommandType.ChatInput,
	description: 'Ping Pong!!',
	async commandRun(interaction) {
		return interaction.reply({ content: 'Pong!', ephemeral: true });
	},
	async messageRun(message) {
		return message.channel.send('Pong!');
	},
});
Listeners

Example

import { Listener } from '#lib/structures';

export default new Listener({
	event: 'ready',
	once: true,
	run(client) {
		client.logger.info(`Logged in as ${client.user.tag}`);
	},
});

Contributing

To contribute to this repository, feel free to fork the repository and make changes. Once you have made your changes, you can submit a pull request. A change should have a valid reason, and features should be added only if it's basic.

  1. Fork the repository and select the main branch.
  2. Create a new branch and make your changes.
  3. Make sure you use a proper code formatter. 2
  4. Make sure you have a good commit message.3
  5. Push your changes.
  6. Submit a pull request here.

Footnotes

  1. It's recommended to have git installed on your machine.

  2. We recommend using prettier to style your code.

  3. We strongly follow the Commit Message Conventions. This is important when commiting your code for a PR.

About

A simple discord bot with custom handler made in discord.js v14

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published