discord.js-handler
TypeScript icon, indicating that this package has built-in type declarations

1.3.2 • Public • Published

discord.js-handler


Simple yet powerful handler for discord.js.

downloads npm version minified size dependencies update rate code quality license


Features 📋

  • Organized and class-oriented
  • CommonJS and EcmaScript friendly
  • Typings included
  • Categories and recursive events and commands

Installation 🔥

npm 🐿️

npm install discord.js-handler

Yarn 🧶

yarn add discord.js-handler

Usage 🚀

Activation example ✔️

const { Client } = require('discord.js');
const { Handler } = require('discord.js-handler');
 
const handler = new Handler({
  client: new Client(),
  token: 'TOKEN',
  eventsFolder: './events',
  commandsFolder: './commands',
});
 
try {
  handler.login();
  handler.run();
} catch (e) {
  console.error(e);
}

Event example 📡

const { EventListener } = require('discord.js-handler');
 
module.exports = class MessageEvent extends EventListener {
  constructor() {
    super({
      event: 'message',
      listener: async ({ handler }, message) => {
        try {
          await handler.importCommands('PREFIX', message);
 
          await message.react('💡');
        } catch (e) {
          console.error(e);
        }
      },
    });
  }
};

Command example 📡

const { CommandListener } = require('discord.js-handler');
 
module.exports = class PingCommand extends CommandListener {
  constructor() {
    const parameters = {
      aliases: ['ping', 'pong'],
      listener: async ({ client, message }) => {
        try {
          await message.reply(`Pong! :ping_pong: ${Math.round(client.ws.ping)}ms`);
          await message.delete();
        } catch (e) {
          console.error(e);
        }
      },
    };
    super(parameters);
  }
};

Warnings ⚠️

When using commands with the handler, you must specify the commands' folder in the handler settings (commandsFolder parameter) and have a message event, in which you call the importCommands method from the handler instance (Handler.importCommands()), otherwise the commands will not be called (As specified in the event example)

This happens because the handler needs a prefix, and it must be defined on the message event, because you could want the prefix to be dynamic (change from guild to guild)


Login and token management done by the handler is completely optional. If you prefer doing so, create the client instance and login by yourself using discord.js

Feedback 👥

If you want to report an error or give a suggestion, please refer to the following links

Report bug

Give suggestion

License 📝

MIT - hSel3triK

Versions

Current Tags

  • Version
    Downloads (Last 7 Days)
    • Tag
  • 1.3.2
    0
    • latest

Version History

Package Sidebar

Install

npm i discord.js-handler

Weekly Downloads

0

Version

1.3.2

License

MIT

Unpacked Size

34.1 kB

Total Files

30

Last publish

Collaborators

  • el3trik_