1.3.2 โ€ข Published 4 years ago

discord.js-handler v1.3.2

Weekly downloads
9
License
MIT
Repository
github
Last release
4 years ago

discord.js-handler



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

1.3.2

4 years ago

1.3.1

4 years ago

1.3.0

4 years ago

1.2.6

4 years ago

1.2.5

4 years ago

1.2.4

4 years ago

1.2.3

4 years ago

1.2.2

4 years ago

1.2.1

4 years ago

1.2.0

4 years ago

1.1.18

4 years ago

1.1.17

4 years ago

1.1.16

4 years ago

1.1.15

4 years ago

1.1.14

4 years ago

1.1.13

4 years ago

1.1.12

4 years ago

1.1.11

4 years ago

1.1.10

4 years ago

1.1.9

4 years ago

1.1.8

4 years ago

1.1.7

4 years ago

1.1.6

4 years ago

1.1.5

4 years ago

1.1.4

4 years ago

1.1.3

4 years ago

1.1.1

4 years ago

1.1.2

4 years ago

1.0.5

5 years ago

1.0.4

5 years ago

1.0.3

5 years ago

1.0.2

5 years ago

1.0.1

5 years ago

1.0.0

5 years ago