2.1.3 • Published 5 years ago

@yaas/command-handler v2.1.3

Weekly downloads
2
License
MIT
Repository
github
Last release
5 years ago

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!');
  }
};
2.1.3

5 years ago

2.1.2

5 years ago

2.1.1

5 years ago

2.0.3

5 years ago

2.0.2

5 years ago

2.0.1

5 years ago

2.0.0

5 years ago

1.2.1

5 years ago

1.2.0

5 years ago

1.1.0

5 years ago

1.0.1

5 years ago

1.0.0

5 years ago