JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 332
  • Score
    100M100P100Q76535F
  • License ISC

Simply add your custom commands to your Discord Bot.

Package Exports

  • @oscarweb/discord-command
  • @oscarweb/discord-command/src/index.js

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@oscarweb/discord-command) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

Discord Command

Simply add your custom commands to your Discord Bot.

Discord Channel Channel - Discord Command

Console Console - Discord Command

Install

npm install @oscarweb/discord-command 

This package is ESM-only and thus requires Node.js v14 or higher.

Example

// bot.js
import { DiscordCommand } from '@oscarweb/discord-command';

// Custom Commands
import Commands from './custom-commands/index.js';

const options = {
    token: '...TOKEN.DISCORD...',
    commands: Commands
};

new DiscordCommand(options).init();

Add your custom commands.

// custom-commands/index.js
import MyCommand from './MyCommand.js';

// You can add a method name for to custom callback.
const Commands = [
    {
        name: '!test',
        class: MyCommand
    },
    {
        name: '!hi',
        class: MyCommand,
        method: 'hi',
        bot: true // Enable reading for bots. Default: false
    }
];

export default Commands;

Get methods defined if you extend your class

// custom-commands/MyCommand.js
import { Command } from '@oscarweb/discord-command';

class MyCommand extends Command{
    /**
     * Custom constructor
     * -
     * @param {Object} message
     */
    // constructor(message){
    // 	super(message); // parent constructor

    // 	this.custom_var = message.content.split(' ');
    // }

    /**
     * Default callback
     * -
     */
    run(){
        this.reply('Test command on #'+this.getChannelName());
    }

    /**
     * Custom callback
     * -
     */
    hi(){
        this.send('hi '+this.getAuthorCompose()+' !!!');
    }
}

export default MyCommand;

Your package.json

{
    "type": "module"
}

Ready

node bot.js