(by old name vnft-commandhandler)
(vnftjs)
vnftjs
Discord CommandHandler for TypeScript or JavaScript
Table of Contents
Class: CommandHandler
the extended discord.js Client
prefix
the prefix for the commands, .
is set by default.
loadCommands(path)
loads all exported command instances of the specified path.
loadScripts(path)
loads all exported script instances of the specified path and triggers them after the client has successfully logged in.
enableHelp()
adds the .help command
enableDebug()
reloads the source file of a command before execution. allows editing commands while the bot is running.
Class: Command
name
the main trigger for the command (without prefix)
funct
the function that gets triggered with the call of the command.
parameters: (client: Client, message: Message, args: string)
Client: the discord client ( extended with the commandhandler )
Message: the message that triggered the command
args: the entire string after the commandname (e.g. .help ping → args:"ping")
addAlias(name)
alternative names for the command, which should also trigger it.
addUserWhitelist(user)
limites the use of the command to those who are described in the whitelist
as long as they are not in the blacklist
addUserBlacklist(user)
disallowes the use of the command to those who are described in the blacklist
even if they are in a whitelist
addRoleWhitelist(role)
restricts the use of the command to those described in the whitelist.
as long as they are not blacklisted.
addRoleBlacklist(role)
prohibits the use of the command by those described in the blacklist.
even if they are on a whitelist.
enableHelp()
adds the .help command
helpColor
sets the color of the richEmbed at the help reply
description
description of the command in .help <command>
usage
usage-description of the parameters in .help <command>
Class: Script
funct
the function that gets executed after the client has successfully logged in.
parameters: (bot: Client)
Client: the discord client ( extended with the commandhandler )
interval
time in ms in which the script-function should be repeated
(negative numbers are disabling the repeat, -1 is the default value)
Examples
JavaScipt
Structure for this example
.
├── main.js
├── commands/
│ ├── ping.js
│ ├── neko.js
│ └── setActivity.js
└── scripts/
├── startAsDnd.js
└── tbd
Code
main.js
const CommandHandler = ;const path = ; const client = ;clientprefix = "!"; client; client;
commands/ping.js
const Command = ; const pingCommand = ;pingCommandname = "ping"; pingCommand { message;}; moduleexports = pingCommand;
commands/neko.js
const Command = ;const axios = ; const neko = ;nekoname = "neko";neko; // ↓ !help gives out the description "Sends a picture of a cat" and !neko without arguments as usagenekodescription = "Sends a picture of a cat";nekousage = ""; nekofunct = async { var meow = await axios; message;}; moduleexports = neko;
commands/activity.js
const Command = ; const activity = ;activityname = "setActivity";activity; // ↓ only the user with the id "397063436049186818" can now execute this commandactivity; activityfunct = async { await clientuser; message;}; moduleexports = activity;
scripts/startAsDnd.js
; ; status.funct = module.exports = status;
TypeScript
Structure for this example:
src/
├── main.ts
├── commands/
│ ├── ping.ts
│ ├── neko.ts
│ └── setActivity.ts
└── scripts/
├── startAsDnd.ts
└── tbd
Code
main.ts
;; ;client.prefix = "!"; client.loadCommandspath.join__dirname, "commands"; client.login"Discord Token";
commands/ping.ts
;; ;ping.name = "ping"; ping.funct =; ;
commands/neko.ts
;;; ;neko.name = "neko";neko.addAlias"cat"; // ↓ !help gives out the description "Sends a picture of a cat" and !neko without arguments as usageneko.description = "Sends a picture of a cat";neko.usage = ""; neko.funct = ; ;
commands/setActivity.ts
;; ;activity.name = "setActivity";activity.addAlias"activity"; // ↓ only the user with the id "397063436049186818" can now execute this commandactivity.addUserWhitelistu.id == "397063436049186818"; activity.funct = ; ;
scripts/startAsDnd.ts
; ; status.funct = ;