From 2c03818793c55a9ad7c90621b9bd364046c8d86d Mon Sep 17 00:00:00 2001 From: Indian Ocean Roleplay <43092101+oceanroleplay@users.noreply.github.com> Date: Sat, 19 Jun 2021 02:44:45 +0530 Subject: [PATCH] Fix: slash command options parsing ### Issue 1. create a slash command with two optional options, example: /test option_a option_b 2. now on discord use this command as ``/test option_b: 123`` (here we are using option_b only and leaving option_a blank) 3. when discord.ts try to execute the original command, parameter passed are ``[123, undefined]`` (which is the issue, because it was suppose to ``[undefined, 123]``) ### Fix I have looked at the code, I think, this suggested approach is more appropriate. Thanks --- src/decorators/classes/DSlash.ts | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/src/decorators/classes/DSlash.ts b/src/decorators/classes/DSlash.ts index f9663185..2dd661f2 100644 --- a/src/decorators/classes/DSlash.ts +++ b/src/decorators/classes/DSlash.ts @@ -143,10 +143,6 @@ export class DSlash extends Method { parseParams(interaction: CommandInteraction) { const options = this.getLastNestedOption(interaction.options); - const values = this.options.map((opt, index) => { - return options[index]?.value; - }); - - return values; + return this.options.sort((a, b) => a.index - b.index).map((op) => options.find((o) => o.name === op.name)?.value); } }