From dce81db74fee15a4cd408e5d38f832e218f472cb Mon Sep 17 00:00:00 2001 From: Alexzander Flores Date: Mon, 11 Oct 2021 17:10:06 -0700 Subject: [PATCH] Fix another slash command bug --- dist/commands/slash.js | 42 +++++++++++++++++++++----------------- package.json | 2 +- src/commands/slash.ts | 46 +++++++++++++++++++++++++----------------- 3 files changed, 52 insertions(+), 38 deletions(-) diff --git a/dist/commands/slash.js b/dist/commands/slash.js index 480a864..9200f13 100644 --- a/dist/commands/slash.js +++ b/dist/commands/slash.js @@ -35,15 +35,18 @@ module.exports = { let allSlashCommands = []; if (global.size) { global.forEach((cmd) => { - const newString = `${cmd?.name}: ${cmd?.id}\n`; - if (!allSlashCommands[counter]) { - allSlashCommands[counter] = ''; - } - if (allSlashCommands[counter].length + newString.length < 1024) { - allSlashCommands[counter] += newString; - } - else { - allSlashCommands[++counter] += newString; + if (cmd && cmd.name) { + const newString = `${cmd.name}: ${cmd.id}\n`; + if ((allSlashCommands[counter] || []).length + newString.length < + 1024) { + allSlashCommands[counter] ??= ''; + allSlashCommands[counter] += newString; + } + else { + ++counter; + allSlashCommands[counter] ??= ''; + allSlashCommands[counter] += newString; + } } }); } @@ -60,15 +63,18 @@ module.exports = { let guildOnlyCommands = []; if (guildOnly.size) { guildOnly.forEach((cmd) => { - const newString = `${cmd.name}: ${cmd.id}\n`; - if (!guildOnlyCommands[counter]) { - guildOnlyCommands[counter] = ''; - } - if (guildOnlyCommands[counter].length + newString.length < 1024) { - guildOnlyCommands[counter] += newString; - } - else { - guildOnlyCommands[++counter] += newString; + if (cmd && cmd.name) { + const newString = `${cmd.name}: ${cmd.id}\n`; + if ((guildOnlyCommands[counter] || []).length + newString.length < + 1024) { + guildOnlyCommands[counter] ??= ''; + guildOnlyCommands[counter] += newString; + } + else { + ++counter; + guildOnlyCommands[counter] ??= ''; + guildOnlyCommands[counter] += newString; + } } }); } diff --git a/package.json b/package.json index a2ca5b8..2d6fc79 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "wokcommands", - "version": "1.5.2", + "version": "1.5.3", "main": "dist/index.js", "typings": "./typings.d.ts", "scripts": { diff --git a/src/commands/slash.ts b/src/commands/slash.ts index 870a459..cf26e25 100644 --- a/src/commands/slash.ts +++ b/src/commands/slash.ts @@ -49,16 +49,20 @@ export = { if (global.size) { global.forEach((cmd: ApplicationCommand) => { - const newString = `${cmd?.name}: ${cmd?.id}\n` - - if (!allSlashCommands[counter]) { - allSlashCommands[counter] = '' - } + if (cmd && cmd.name) { + const newString = `${cmd.name}: ${cmd.id}\n` - if (allSlashCommands[counter].length + newString.length < 1024) { - allSlashCommands[counter] += newString - } else { - allSlashCommands[++counter] += newString + if ( + (allSlashCommands[counter] || []).length + newString.length < + 1024 + ) { + allSlashCommands[counter] ??= '' + allSlashCommands[counter] += newString + } else { + ++counter + allSlashCommands[counter] ??= '' + allSlashCommands[counter] += newString + } } }) } else { @@ -85,16 +89,20 @@ export = { if (guildOnly.size) { guildOnly.forEach((cmd: ApplicationCommand) => { - const newString = `${cmd.name}: ${cmd.id}\n` - - if (!guildOnlyCommands[counter]) { - guildOnlyCommands[counter] = '' - } - - if (guildOnlyCommands[counter].length + newString.length < 1024) { - guildOnlyCommands[counter] += newString - } else { - guildOnlyCommands[++counter] += newString + if (cmd && cmd.name) { + const newString = `${cmd.name}: ${cmd.id}\n` + + if ( + (guildOnlyCommands[counter] || []).length + newString.length < + 1024 + ) { + guildOnlyCommands[counter] ??= '' + guildOnlyCommands[counter] += newString + } else { + ++counter + guildOnlyCommands[counter] ??= '' + guildOnlyCommands[counter] += newString + } } }) } else {