3.0.3 • Published 4 months ago

command-handler-discord v3.0.3

Weekly downloads
19
License
MIT
Repository
github
Last release
4 months ago

Command handler discord

NPM

Installation

yarn add command-handler-discord
or
npm install command-handler-discord

1000000 - 5.490s 1 - 1.95 - 5ms

Usage

// Import package in your project
const Handler = require('command-handler-discord');

// Initialize with commands directory path and options, command file name will be command name and parser will try to found builder command in with name COMMAND-NAME_builder
const Handler = Handler.createHandler('./myCommands', {
  pefix: "!", // see https://www.npmjs.com/package/discord-cmd-parser
  useQuotes: true, // see https://www.npmjs.com/package/discord-cmd-parser
  namedSeparator: "-", // see https://www.npmjs.com/package/discord-cmd-parser
  quotesType: '"', // see https://www.npmjs.com/package/discord-cmd-parser
  checkParentPermission: true, // iterate from current command to its parrent and check if command caller match permisions lever for each of them
  adminRoles: [] // admin roles ids
  modRoles: [] // mod roles ids
})
 // Command name equal to filename without .js extension
 // Command file code example
 // filename: test.js
 module.exports = {
	description: '5',
	aliases: ['alias_test'], // only if you need aliases for command
	builder: ['test_2'], // only if you need builder commands
  delay: 5,
  exec: (caller: GuildMember, args) => {} // required
};
// Builder commands should go into separate folder with name [parent_command_name]_builder and file should have a name like in builder array of parrent command.
// Builder command file example
// filename: test_2.js
module.exports = {

	description: 'some description',
	aliases: ['alias_test_2'], // only if you need aliases for command
	delay: 5,
  builder: ['test_3'], // only if you need builder command
  exec: (caller: GuildMember, args) => {} // required
};
// You can define other filds in your command file, they will be parsed and you can use as you like

Handler.command("!test test_2") // Will return promise, promise will be resolved if command is found and rejected if not. use this to check if the command exists
// Example of the resolve value
{
  args // args without command names and alises see https://www.npmjs.com/package/discord-cmd-parser
  cmd // there will be the test_2 command object
  cmds // array of commands, that are the chain to invoked command, in that case there will be [test command object, test_2 command object]
  exec(caller: GuildMember, ?customArgs: any) //  will invoke exec function from test_2 command
}

Methods

MethodreturnDescription
command(string: string)Promise<{ args, cmd, cmds, ecec() }>Parses command and args from string.
setPrefix(prefix: string)voidSet a new prefix for commands
disableQuotes()voidDisable long args in quotes
enableQuotes()voidEnable long args in quotes
setNamedSeparator(separator: string)voidSet a new named separator
reinit(commandsDir: stringstring[])voidreinit handler with a new commands directory

Properties

PropetryreturnDescription
CommandsMap<commandName:string, command: Command>Map object with commands.
AliasesMap<commandAlias:string, command: Command>Map object with aliases.

License

MIT License

Copyright (c) 2020 T-Rumibul t.rumibul.work@gmail.com

3.0.3

4 months ago

3.0.2

3 years ago

3.0.1

3 years ago

3.0.0

3 years ago

2.1.2

4 years ago

2.1.1

4 years ago

2.1.0

4 years ago

2.0.9

5 years ago

2.0.8

5 years ago

2.0.7

5 years ago

2.0.5

5 years ago

2.0.6

5 years ago

2.0.4

5 years ago

2.0.3

5 years ago

2.0.2

5 years ago

2.0.1

5 years ago

2.0.0

5 years ago

1.3.0

5 years ago

1.2.1

5 years ago

1.2.0

5 years ago

1.1.0

5 years ago

1.0.0

5 years ago