Git Product home page Git Product logo

essence's Introduction

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

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.