npm install discordjs-cmds --save
This project is currently in an early development phase, which means, that there could be some unidentified bugs. Also, there will be much more functions added and advanced later! Feel free to post issues or pull request if you noticed a bug or if you have improvement suggestions!
Implement the library, create your bot framework and create an instance of the CmdParser
const { Client } = require('discord.js')
const { CmdParser } = require('discordjs-cmds')
// Creating bot instance
const bot = new Client()
// Creating CmdParser Instance
const cmd = new CmdParser(bot, "-")
// Login the bot instance with your discord token
bot.login(/*bot token*/)
Now, create some methods for commands somewhere
function cmd_say(msg, args) {
msg.channel.send(args.join(' '))
}
function cmd_ping(msg, args) {
msg.channel.send('Pong!')
}
// ...
Then, you can register your commands like following
cmd.register(cmd_say, "say", ["tell", "send"], "Send a message with the bot", "-say <msg>", cmd.type.CHAT, 1)
.register(cmd_ping, "ping")
For permissions, you can register specific permission levels for specific roles
cmd.setPerms(["2134792837489213749", "2319480812347123431"], 1)
.setPerms("8757023480239487232", 2)
If you want to react on some events the CmdParser event manager fires, use it like following
cmd.event.on('commandFailed', (errtype) => console.log(`Failed Command: ${errtype}`))
There are some default implemented commands:
Sends the user a list of commands via DM
Get the help message of a registered command
All changelogs (after version 0.3.0
) you can find in the CHANGELOG.md.
- Add option + function to give guild owners higher perm lvl
- Method to register bot host with max perm lvl
- Guild specific prefixes
- Custom command types
- Aliases
- Permissions
- Detailed help command
new CmdParser(botinstance, prefix)
Parameter | Type | Optional (Default) | Description |
---|---|---|---|
botinstance | Discord.Client | no | The instance of the bots client |
prefix | string | no | The default prefix commands should be executed with |
Returns CmdParser
this
Some standardised enum like types for commands
ADMIN
:ADMIN
GUILDADMIN
:GUILDADMIN
MODERATION
:MODERATION
FUN
:FUN
SETTING
:SETTING
CHAT
:CHAT
MISC
:MISC
Some standardised enum like error codes for event emitter
WRONG_INVOKE
:0
NOT_PERMITTED
:1
EXECUTION_ERROR
:2
WRONG_CHANNEL
:3
Emitted when command was executed successfully
Parameter | Type | Description |
---|---|---|
msg | Discord.Message | Message which command was parsed from |
Emitted when command could not be parsed correctly
Parameter | Type | Description |
---|---|---|
errortype | CmdParser.errors | Error type |
msg | Discord.Message | Message command should has parsed from |
error | string | Error description / details |
Emitted when command could not be written correctly into log file
Parameter | Type | Description |
---|---|---|
msg | Discord.Message | Message from sent command |
err | string | Error description / details |
Register commands with their properties
Parameter | Type | Optional (Default) | Description |
---|---|---|---|
func | function | no | Function which will be executed |
invoke | string | no | Primary invoke to access command |
aliases | string[] | yes ([] ) |
Aliases to access command |
description | string | yes ("No description" ) |
Description shown in help command |
help | string | yes (No help ) |
Help displayed in help option |
type | CmdParser.type | yes (CmdParser.type.MISC ) |
Type of command |
perm | number | yes (0 ) |
Permission level of command |
Returns CmdParser
this
Define permission levels to specified roles
Parameter | Type | Optional (Default) | Description |
---|---|---|---|
roles | string / string[] / Discord.Role / Discord.Role[] | no | Role ID's of roles |
permlvl | number | no | Permission LvL roles will get refered to |
Returns CmdParser
this
Edit some default options of command parser
Parameter | Type | Optional (Default) | Description |
---|---|---|---|
options.msgcolor | number | yes (0xd2db2b ) |
Color of some messages like help message |
options.cmdlog | boolean | yes (true ) |
Send defaultly logs into console after command was executed |
options.msgedit | boolean | yes (true ) |
Parse edited messages like send messages as command |
options.logfilepath | string | yes (null ) |
Path for command log file |
options.timeformat | string | yes (null ) |
Time formatD - DayM - MonthY - Yearh - Hourm - Minutes - Second |
options.invoketolower | boolean | yes (true ) |
Set if invoke should be converted to lowercase or not |
options.guildonwerperm | number | yes (null ) |
Set the specific permission level for guild owners |
Returns CmdParser
this
Set the Discord account of the host of the bot for maximum permission
Parameter | Type | Optional (Default) | Description |
---|---|---|---|
host | Discord.Member / Discord.User / string / number | no | Discord User / Member / User ID of bots host |
Returns CmdParser
this
Set the specific prefixes for guils
Parameter | Type | Optional (Default) | Description |
---|---|---|---|
guildpres | object | no | Like example: {"23463623423452345": "-", "2374827347829347": "."} |
Returns CmdParser
this
Get the permission level of a member
Parameter | Type | Optional (Default) | Description |
---|---|---|---|
memb | Discord.Member | no | Member to get perm lvl from |
Returns number
Permission Level
Add some custom command types. In registration, they can used like the defualt types
cmdParser.type.YOURTYPE
or directly with the string"YOURTYPE"
. Keep in mind, that command types are always processed to uppercase, so also if you enter lowercase, it wil lautomatically converted to uppercase.
Parameter | Type | Optional (Default) | Description |
---|---|---|---|
typename | string / string[] | no | new typename as string or array |
Returns CmdParser
this
Parse message as command. Defaultly, the CmdParser creates a listener for messages in public text channels which listens to messages, so just use this if you want to parse commands for example in private chats.
Parameter | Type | Optional (Default) | Description |
---|---|---|---|
msg | Discord.Message | no | Message to parse command |
Returns CmdParser
this
Send a help message into a channel. If
invoke
is not given, sending full command list, else sending information about given command invoke
Parameter | Type | Optional (Default) | Description |
---|---|---|---|
chan | Discord.Channel | no | Channel where message will be send |
invoke | string | yes (null ) |
Send details of given command or full list of cmds |
Returns Discord.Message
Message sendt into channel