@oscarweb/discord-command
v1.1.2
Published
Simply add your custom commands to your Discord Bot.
Downloads
34
Maintainers
Readme
Discord Command
Simply add your custom commands to your Discord Bot.
Discord Channel
Console
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