0.1.1 • Published 7 months ago

djs-ghandler v0.1.1

Weekly downloads
-
License
ISC
Repository
github
Last release
7 months ago

djs-ghandler: A Library for Discord.js Projects

djs-ghandler is an easy-to-use JavaScript library that simplifies the process of handling commands, events, and validations in your Discord.js projects.

Discord.js version supported: v14

Installation

To install djs-ghandler, simply run the following command:

For npm:

npm install djs-ghandler

Usage

// index.js
const { Client, GatewayIntentBits } = require("discord.js");
const { Handler } = require("djs-ghandler");

const client = new Client({
    intents: [Object.keys(GatewayIntentBits)]
});

const handler = new Handler(client, {
    commandsPath: "COMMAND_PATH", // You can using path module from node.js
    eventPath: "EVENT_PATH", // Same like commandPath, You can using path module from node.js
    ext: ".js" // .js is a deafult extension in this class you can chance it to readable script like .ts
});

client.login("TOKEN");

File Structure

Any file inside the commands directory will be considered a command file, so make sure it properly exports an object. Like this:

// commands/ping.js
const { SlashCommandBuilder } = require('discord.js');

module.exports = {
  data: new SlashCommandBuilder().setName('ping').setDescription('Pong!'),

  execute: ({ interaction, client, fileData }) => {
    interaction.reply(`Pong! ${client.ws.ping}ms`);
  },
};
  • interaction
  • client is the discord.js Client instance.

Events

DJS-GHandler assumes a specific file structure for your events. Here's an example of what your file structure could look like:

events/
├── ready/
|	├── console-log.js
|	└── webhook.js
|
└── messageCreate/
	├── auto-mod/
	|	├── delete-swear-words.js
	|	└── anti-raid.js
	|
	└── chat-bot.js

Make sure each file exports a default function. Like this:

// events/ready/console-log.js
module.exports = ({ argument, client }) => {
  console.log(`${client.user.tag} is online.`);
};
  • argument is the argument you receive from the event being triggered (you can name this whatever you want). For example, the messageCreate event will give you an argument of the message object.
  • client is the discord.js Client instance.

0.1.1

7 months ago

0.0.6-rebuild

8 months ago

0.0.5-remake

8 months ago

0.0.3-remake

8 months ago

0.0.2-remake

8 months ago

0.0.1

8 months ago

0.1.6

1 year ago

0.1.5

1 year ago

0.1.4

1 year ago

0.1.3

1 year ago

0.1.2

1 year ago