@gary50613/discord.js-command-handler
Advanced tools
Comparing version 2.3.1 to 2.3.2
@@ -47,18 +47,21 @@ const fs = require("fs"); | ||
*/ | ||
async register(command) { | ||
if (Array.isArray(command)) command.forEach(cmd => this.register(cmd)); | ||
async register(...command) { | ||
if(Array.isArray(command[0])) | ||
command = command[0] | ||
if (!command instanceof Command) | ||
throw new TypeError(`command must be Command`) | ||
command.forEach(cmd => { | ||
if (!cmd instanceof Command) | ||
throw new TypeError(`command must be Command`) | ||
this.commands.push(command) | ||
this.commands.push(cmd) | ||
if (command?.group?.length > 0) { | ||
let group = this.groups.get(command?.group) | ||
if (!group) { | ||
group = new Group(command?.group) | ||
this.groups.set(command.group, group) | ||
} | ||
group.register(command) | ||
} | ||
if (cmd?.group?.length > 0) { | ||
let group = this.groups.get(cmd?.group) | ||
if (!group) { | ||
group = new Group(cmd?.group) | ||
this.groups.set(cmd.group, group) | ||
} | ||
group.register(cmd) | ||
} | ||
}) | ||
@@ -65,0 +68,0 @@ return this |
@@ -37,8 +37,10 @@ const Interaction = require("../Base/Interaction") | ||
async register(interaction) { | ||
if(Array.isArray(interaction)) | ||
return interaction.forEach(this.register) | ||
if(!interaction instanceof Interaction) | ||
throw new TypeError(`interaction must be Interaction`) | ||
this.interactions.set(interaction?.name, interaction) | ||
async register(...interaction) { | ||
if(Array.isArray(interaction[0])) | ||
interaction = interaction[0] | ||
interaction.forEach(int => { | ||
if(!int instanceof Interaction) | ||
throw new TypeError(`interaction must be Interaction`) | ||
this.interactions.set(int?.name, int) | ||
}) | ||
} | ||
@@ -45,0 +47,0 @@ |
{ | ||
"name": "@gary50613/discord.js-command-handler", | ||
"version": "2.3.1", | ||
"version": "2.3.2", | ||
"description": "simple discord.js command handler", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -53,3 +53,3 @@ # djs-command-handler | ||
// or register multiple command at the same time | ||
bot.commands.register([new ping(), ..., ...]) | ||
bot.commands.register(new ping(), ..., ...) | ||
@@ -111,3 +111,3 @@ // listen to event | ||
// or register multiple command at the same time | ||
bot.commands.register([new ping(), ..., ...]) | ||
bot.commands.register(new ping(), ..., ...) | ||
@@ -114,0 +114,0 @@ // listen to event |
27983
535