Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/ulughann/essence

Pure, Type-Safe and Minimal template for Discord.js v14 and Slash Commands
https://github.com/ulughann/essence

altyapi altyapi-bot discord discord-bot discord-js

Last synced: 2 months ago
JSON representation

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

Awesome Lists containing this project

README

        

Essence logo

Essence

Pure, Type-Safe and Minimal template for Discord Bots using [Discord.js v14](https://discord.js.org/)

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`

```bash
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:

```ts
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:

```ts
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](https://github.com/onrirr/noml) config file.

### Structured Logging
The `console.ts` util is used for structured logging. It is used as follows:

```ts
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;

```ts
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](https://discordjs.guide/popular-topics/intents.html).

Requirements

- [Node.js](https://nodejs.org/en/) v16 or higher

![Stats](https://repobeats.axiom.co/api/embed/d86852e3898713e1283f4916a29d73a701c9266c.svg "Repobeats analytics image")