Skip to content
Permalink
Branch: master
Find file Copy path
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
144 lines (113 sloc) 3.67 KB
description
Create your own command

Creating a command

You can contribute to Wump by creating your own command, this is very easy if you have a basic understanding of Node.JS

extData of a command

Every command has extData, this basically is the command-specific settings object, it's structured as followed:

{% code-tabs %} {% code-tabs-item title="_base.js" %}

cmd.extData = {
    // Information
    path       : undefined, // The config path of the command [`wump.utility.ping` for example] ( optional )
    name       : null,      // Command name        ( required )
    syntax     : null,      // Command syntax      ( optional )
    bearer     : 'wump',    // Command bearer      ( required )
    aliases    : [],        // Command aliases     ( optional )
    argument   : [],        // Command arguments   ( optional )
    description: null,      // Command description ( optional )
    // Checks
    hidden     : false,     // Hidden from view    ( true / false )
    enabled    : true,      // Enabled or disabled ( true / false )
    cooldown   : 1000,      // Command cooldown    ( optional )
    category   : 'General', // Command category    ( required )
    ownerOnly  : false,     // Owner only          ( true / false )
    guildOnly  : false,     // Guild only          ( true / false )
    permissions: []         // Bot permissions     ( optional )
}

{% endcode-tabs-item %} {% endcode-tabs %}

Base command class

A command is structured as followed:

{% code-tabs %} {% code-tabs-item title="_base.js" %}

const { DiscordCommand } = requir
e('../../core');

/*
  Replace <name> with your command's name
  Replace <syntax> with your command's syntax
  Replace <author> with your name
  Replace <description> with your description
*/
 


module.exports = class <name> extends DiscordCommand {
  constructor(bot) {
    super(bot, {
      path        : undefined,
      name        : '<name>',
      syntax      : '<syntax>',
      bearer      : '<author>',
      aliases     : [],
      argument    : [],
      description: '<description>',

      hidden     : false,
      enabled    : true,
      cooldown   : 1000,
      category   : 'Utility',
      ownerOnly  : false,
      guildOnly  : false,
      permissions: []
    });

    Object.freeze(this);
    Object.freeze(this.static);
  }

  async execute(msg, args, user, guild) {
    // ...
  }

  _localize(msg, extData = {}) {
    try {
      if (!msg) throw 'INVALID_STRING';

      // ...
    } catch (ex) {
      return `LOCALIZE_ERROR:${ex.code}`;
    }
  }
};

{% endcode-tabs-item %} {% endcode-tabs %}

Creating your command

A command should be put inside of Command.emitas followed:

{% code-tabs %} {% code-tabs-item title="_base.js" %}

emit(msg, args, user, guild) {
    console.log(msg, args, user, guild);
    // Localizing
    console.log(this._localize(msg.author.locale.cooldown, msg.author);
}

{% endcode-tabs-item %} {% endcode-tabs %}

Localizing your command

Localizing is done with the private Command._localize function as followed:

{% code-tabs %} {% code-tabs-item title="_base.js" %}

  _localize(msg, extData = {}) {
    try {
      if (!msg) throw 'INVALID_STRING';

      return msg
        .replace(/{e\.user\.id}/, extData.id)
    } catch (ex) {
      return `LOCALIZE_ERROR:${ex.code}`;
    }
  }

{% endcode-tabs-item %} {% endcode-tabs %}

How to submit

After you've tested and linted your command, you can submit it by creating a pull request on GitHub.
It may take some time for your pull request to be reviewed

You can’t perform that action at this time.