From b095b995ec6a4833ece60ed4e7cbda0d088c5cdd Mon Sep 17 00:00:00 2001 From: ITOH <72305210+itohatweb@users.noreply.github.com> Date: Sun, 7 Mar 2021 15:46:08 +0100 Subject: [PATCH] fix upsertSlashCommand & upsertSlashCommands --- src/api/handlers/webhook.ts | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/src/api/handlers/webhook.ts b/src/api/handlers/webhook.ts index 74fda402b..4f3eef451 100644 --- a/src/api/handlers/webhook.ts +++ b/src/api/handlers/webhook.ts @@ -336,12 +336,17 @@ export async function upsertSlashCommand( guildID?: string, ) { // Use ... for content length due to unicode characters and js .length handling - if ([...options.name].length < 2 || [...options.name].length > 32) { + if ( + options.name && + ([...options.name].length < 2 || [...options.name].length > 32) + ) { throw new Error(Errors.INVALID_SLASH_NAME); } if ( - [...options.description].length < 1 || [...options.description].length > 100 + options.description && + ([...options.description].length < 1 || + [...options.description].length > 100) ) { throw new Error(Errors.INVALID_SLASH_DESCRIPTION); } @@ -371,12 +376,17 @@ export async function upsertSlashCommands( ) { const data = options.map((option) => { // Use ... for content length due to unicode characters and js .length handling - if ([...option.name].length < 2 || [...option.name].length > 32) { + if ( + option.name && + ([...option.name].length < 2 || [...option.name].length > 32) + ) { throw new Error(Errors.INVALID_SLASH_NAME); } if ( - [...option.description].length < 1 || [...option.description].length > 100 + option.description && + ([...option.description].length < 1 || + [...option.description].length > 100) ) { throw new Error(Errors.INVALID_SLASH_DESCRIPTION); }