Skip to content
/ essence Public template

Pure, Type-Safe and Minimal template for Discord.js v14 and Slash Commands

Notifications You must be signed in to change notification settings

ulughann/essence

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Essence logo

Essence

Pure, Type-Safe and Minimal template for Discord Bots using Discord.js v14

Get Started

After cloning the repository with git clone, add your bot token to the config file

config:

token = XXXXXXXXXXXXXX_XXXXXXX_XXXXXXXXXXXXX

Then, install the dependencies and run the bot with npm run dev

npm install
npm run dev

Project Structure

Essence
├── src
│   ├── commands
│   │   ├── command.ts
│   │   └── subdirectory/
│   │       └── command.ts
│   ├── events
│   │   ├── event.ts
|   |
│   └── utils
│   |   ├── ...
│   |
│   └── index.ts
│
├── config
├── logs.yml
├── .gitignore
├── package.json
├── tsconfig.json
└── nodemon.json

Commands

Commands are positioned in the commands/ directory (of course subdirectories to commands/ are allowed, eg. commands/moderation/ban.ts), and are loaded automatically by the bot. Commands are structured as follows:

import { SlashCommandBuilder } from "@discordjs/builders";

export default {
  data: new SlashCommandBuilder()
  .setName("ping")             // check out the command builder docs for more info
  .setDescription("Pong!"),    
  run: async (client, interaction) => {
    // comamnd body
  }
};

Events

Events are positioned in the events/ directory, and are loaded automatically by the bot. Events are structured as follows:

import { Client } from "discord.js";

export default {
	name: 'ready',
	once: true, // true if event should only be executed once
	execute(client: Client) {
		// event body
	},
};

Utils

Utils are positioned in the utils/ directory, and are extra code that helps you with your bot. Utils have no structure, and can be anything you want them to be. By default there is a console.ts util for structured logging, log.ts util for logging to a file and the configParser.js to read the NOML config file.

Structured Logging

The console.ts util is used for structured logging. It is used as follows:

import { Print, Warn, Inform, Error } from "./utils/console";

Print("Hello World!");
Warn("Hello World!");
Inform("Hello World!");
Error("Hello World!");

Logging to a file

The log.ts util is used for logging to a file. It is used as follows:

Example;

import { Error } from "./utils/console";
import { $l } from "./utils/log";

catch (error) {
  Error("Hello World!", $l(error));
}

(this adds the error to the log file in logs.yml, and logs it to the console)

Utils/intents.ts

This file is used to define the intents, shards and partials for your bot. By default, the intents are set to GUILDS and GUILD_MESSAGES. You can read more about intents here.

Requirements

About

Pure, Type-Safe and Minimal template for Discord.js v14 and Slash Commands

Topics

Resources

Stars

Watchers

Forks