@oscarweb/discord-command

0.5.0 • Public • Published

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';

new DiscordCommand('...TOKEN.DISCORD...', Commands).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'
	}
];

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

Package Sidebar

Install

npm i @oscarweb/discord-command

Weekly Downloads

3

Version

0.5.0

License

ISC

Unpacked Size

9.38 kB

Total Files

10

Last publish

Collaborators

  • oscarweb