Skip to content

Commit

Permalink
feat(Utils): checkIfSubOrGroup, avoid duplications
Browse files Browse the repository at this point in the history
  • Loading branch information
xhyrom committed Jan 18, 2022
1 parent 73d0a4b commit 59d2aa0
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions src/lib/util/Util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export class Util {

const check = options => {
for (const option of options) {
if ([1, 2].includes(option.type)) args.push(option.name);
if (Util.checkIfSubOrGroup(option.type)) args.push(option.name);
else args.push(option.value);

if (option.options) check(option.options);
Expand All @@ -29,7 +29,7 @@ export class Util {

const check = (options, object) => {
for (const option of options) {
if ([1, 2].includes(option.type)) object[option.name] = {};
if (Util.checkIfSubOrGroup(option.type)) object[option.name] = {};
else object[option.name] = option.value;

if (option.options) check(option.options, object[option.name]);
Expand All @@ -40,6 +40,15 @@ export class Util {

return args;
}

/**
* @deprecated We don't support arguments in object/array
* @link https://discord.js.org/#/docs/main/stable/class/CommandInteractionOptionResolver
*/
private static checkIfSubOrGroup(type) {
// Why? Because discord.js v14 (:
return !!['SUB_COMMAND', 'SUB_COMMAND_GROUP', 'Subcommand', 'SubcommandGroup'].includes(type);
}

static isClass(input: any): boolean {
return (
Expand Down

0 comments on commit 59d2aa0

Please sign in to comment.