0.0.3 • Published 1 year ago

umbrae v0.0.3

Weekly downloads
-
License
MIT
Repository
-
Last release
1 year ago

Welcome to Umbrae's Package

This package is designed for developers looking to enhance their Discord bot development activities with ease.

Installation

Before starting, make sure to install the package:

npm i umbrae

Ensure you are using ES6 imports.

Creating Your Application

Here is an example directory structure:

my-project/
├── commands/
│   └── admin/
│       └── ban.js
├── events/   
│   └── message/
│       └── messageCreate.js
├── main.js
└── package.json

In your main.js file, set up your application as follows:

import { App, AppIntents, AppManager } from 'umbrae';

const app = new App({
    intents: [AppIntents.All]
});

const manager = new AppManager(app, {
    commandPath: './commands',
    eventPath: './events',
    clientId: 'YOUR_CLIENT_ID',
    token: 'YOUR_TOKEN',
    guildId: 'YOUR_GUILD_ID' // optional
});

Congratulations! You are halfway there!

Writing a Command

To write a command, follow this structure (example: ban command):

import { CommandBuilder } from 'umbrae';

const command = {
    data: new CommandBuilder()
        .setName('ban')
        .setDescription('Ban a user')
        .setCooldown(8) // set the cooldown to 8 seconds
        .setType('Miscellaneous') // set the type to Miscellaneous (useful for categorizing)
        .addUserOption(option => option.setName('user').setDescription('The user to ban').setRequired(true)),
    async execute(interaction) {
        const user = interaction.options.getUser('user', true);
        const member = interaction.guild.members.cache.get(user.id);
        try {
            await member.ban();
            interaction.reply({ content: `Successfully banned ${user.globalName ?? user.username}`, ephemeral: true });
        } catch (error) {
            interaction.reply({ content: 'An error occurred while trying to ban the user', ephemeral: true });
            console.error(error);
        }
    }
};

export default command;

Writing an Event Handler

To write an event handler, follow this structure (example: messageCreate event):

import { DataBuilder } from 'umbrae';
const data = new DataBuilder();

const event = {
    name: 'messageCreate',
    async execute(message: Message) {
        if (!message.guild || message.author.bot) return;
        console.log(message);
    },
};

export default event;

Using the DataBuilder

The DataBuilder class allows for easy JSON file-based data management. Here is an example of how to use it:

  • Creating a table :
const db = new DataBuilder();
db.create('users');
  • Inserting Data:
db.insert('users', { id: 1, name: 'John Doe' });
  • Retrieving Data:
const users = db.get('users');
console.log(users);
  • Querying Data:
const user = db.query('users', { id: 1 });
console.log(user);

By following these examples, you can effectively manage your data using the DataBuilder class in your project.

How to use ES6

To ensure you are using ES6 imports correctly in your project, follow these steps:

  • Install the necessary dependencies: Make sure you have the required dependencies installed. You can install them using npm:
npm i umbrae
  • Set up your project to use ES6 modules: Ensure your project is configured to support ES6 modules. This can be done by adding the "type": "module" field in your package.json:
{
  "name": "my-project",
  "version": "1.0.0",
  "description": "",
  "main": "main.js",
  "type": "module",
  "scripts": {
    "start": "node main.js"
  },
  "dependencies": {
    "umbrae": "^1.0.0"
  }
}
  • Running your project: With everything set up, you can run your project using the following command:
npm start
0.0.1

1 year ago

0.0.3

1 year ago

0.0.2

1 year ago

1.0.2

1 year ago

1.0.1

1 year ago

1.0.3

1 year ago

1.0.0

1 year ago