1.1.8 • Published 5 years ago
@elchologamer/discord-command v1.1.8
discord-command
Easily handle commands for your Discord bot using discord.js!
Installation
Run the following command on console:
> npm i discord-command --save
Usage
You can create classes that extend the Command
class, and register them on a CommandHandler
variable.
Code examples
JavaScript
const Command, { CommandHandler } = require('discord-command');
const { Client } = require('discord.js');
const bot = new Client();
// A command that sends 'Hello world!'
// to the channel when '!hello' is sent
class HelloCommand extends Command {
constructor() {
super('hello', 'Says "Hello world!" on the channel', null, false);
}
run(event) {
event.channel.send('Hello world!');
}
getHelp() {
return new MessageEmbed()
.setTitle('hello command help')
.setDescription(this.description);
}
}
// Create CommandHandler with the prefix '!'
const handler = new CommandHandler(bot, '!');
handler.addCommands(new HelloCommand());
console.log('Logging in...');
bot.login(process.env.TOKEN);
TypeScript
import Command, { CommandHandler, CommandEvent } from 'discord-command';
import { Client, MessageEmbed } from 'discord.js';
const bot: Client = new Client();
// A command that sends 'Hello world!'
// to the channel when '!hello' is sent
class HelloCommand extends Command {
public constructor() {
super('hello', 'Says "Hello world!" on the channel', null, false);
}
public run(event: CommandEvent): void {
event.channel.send('Hello world!');
}
public getHelp(): MessageEmbed {
return new MessageEmbed()
.setTitle('hello command help')
.setDescription(this.description);
}
}
// Create CommandHandler with the prefix '!'
const handler: CommandHandler = new CommandHandler(bot, '!');
handler.addCommands(new HelloCommand());
console.log('Logging in...');
bot.login(process.env.TOKEN);