vnftjs
This is a bare bones version ofvnft-commandhandler
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.
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.
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; 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; nekofunct = async { var meow = await axios; message;}; moduleexports = neko;
commands/activity.js
const Command = ; const activity = ;activityname = "setActivity";activity; 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.loadCommandspath.join__dirname, "scripts"; client.login"Discord Token";
commands/ping.ts
;; ;ping.name = "ping"; ping.funct =; ;
commands/neko.ts
;;; ;neko.name = "neko";neko.addAlias"cat"; neko.funct = ; ;
commands/setActivity.ts
;; ;activity.name = "setActivity";activity.addAlias"activity"; activity.funct = ; ;
scripts/startAsDnd.ts
; ; status.funct = ;