@yaas/command-handler
TypeScript icon, indicating that this package has built-in type declarations

2.1.3 • Public • Published

Command Handler

ghub-activity-shield npmv-shield MIT

Installation

This one is nice and simple!

With npm:

$ npm install @yaas/command-handler

With yarn:

$ yarn add @yaas/command-handler

Usage

This is meant to simplify creating discord bots that are not single-file

const CommandHandler = require('@yaas/command-handler');
const { Client } = require('discord.js');

const client = new Client();
const CH = new CommandHandler({
  folder: __dirname + '/commands/',
  prefixes: ['?', '>'] // NOTE: prefixes may not contain spaces
});

client.on('message', message => {
  const args = message.content.split(/\s+/g);
  const command = args.shift();

  const cmd = CH.get(command);

  if (cmd === null) return;

  try {
    cmd.run(client, message, args);
  } catch {
    console.error(`There was an error running command: ${cmd.name}`);
  }
});

This should be your file structure:

.
├── index.js
├── node_modules/
│   └── ...
└── commands/
    └── test.js

This is what test.js looks like:

module.exports = class command {
  constructor() {
    this.name = 'test';
    this.aliases = [];
    this.description = '?test';
  }

  async run(client, message, args) {
    message.reply('Test works!');
  }
};

Readme

Keywords

Package Sidebar

Install

npm i @yaas/command-handler

Weekly Downloads

0

Version

2.1.3

License

MIT

Unpacked Size

4.87 kB

Total Files

5

Last publish

Collaborators

  • yaas-dev