@gary50613/discord.js-command-handler
Advanced tools
Comparing version 1.3.0 to 1.4.0
@@ -44,4 +44,7 @@ # djs-command-handler | ||
// 註冊整個資料夾的指令 | ||
commandHandler.commands.loadCommands("./commands") | ||
// 註冊一個指令 | ||
commandHandler.commands.register(ping) | ||
commandHandler.commands.register(new ping()) | ||
@@ -48,0 +51,0 @@ // 或是一次註冊多個指令 |
@@ -0,1 +1,2 @@ | ||
const fs = require("fs"); | ||
const Group = require("../Base/Group"); | ||
@@ -14,6 +15,4 @@ | ||
register(command) { | ||
if(Array.isArray(command)) | ||
return command.forEach(this.register) | ||
if(Array.isArray(command)) command.forEach(cmd => this.register(cmd)); | ||
command = new command() | ||
this.commands.push(command) | ||
@@ -32,2 +31,23 @@ | ||
/** | ||
* @description Register commands in folder | ||
* @param {String} folderPath Path to folder | ||
* @example commandHandler.commands.loadCommands("./commands") | ||
*/ | ||
loadCommands(folderPath) { | ||
if (typeof folderPath === "string") | ||
throw new TypeError(`folderPath must be string, received ${typeof folderPath}`) | ||
fs.readdir(folderPath, (err, files) => { | ||
if (err) return console.error(err) | ||
files.filter(f => f.endsWith(".js")) | ||
.forEach(file => | ||
this.register( | ||
new (require(`${folderPath}${folderPath.endsWith("/") ? "" : "/"}${file}`))() | ||
) | ||
) | ||
}) | ||
} | ||
/** | ||
* @description return command by name or alias | ||
@@ -34,0 +54,0 @@ * @param name command's name or alias |
{ | ||
"name": "@gary50613/discord.js-command-handler", | ||
"version": "1.3.0", | ||
"version": "1.4.0", | ||
"description": "simple discord.js command handler", | ||
@@ -5,0 +5,0 @@ "main": "CommandHandler.js", |
@@ -44,4 +44,7 @@ # djs-command-handler | ||
// load a whole folder's commands | ||
commandHandler.commands.loadCommands("./commands") | ||
// register a command | ||
commandHandler.commands.register(ping) | ||
commandHandler.commands.register(new ping()) | ||
@@ -48,0 +51,0 @@ // or register multiple command at the same time |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
12837
210
120
3