Skip to content

Commit

Permalink
fix: correctly get options of subcommands and subcommandgroups (#126)
Browse files Browse the repository at this point in the history
  • Loading branch information
thewilloftheshadow authored Sep 18, 2024
1 parent 5fc1db7 commit b29eefd
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 8 deletions.
5 changes: 5 additions & 0 deletions .changeset/slow-seas-fix.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@buape/carbon": patch
---

fix: correctly get options of subcommands and subcommandgroups
4 changes: 1 addition & 3 deletions packages/carbon/src/internals/AutocompleteInteraction.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import {
type APIApplicationCommandAutocompleteInteraction,
type APIApplicationCommandInteractionDataBasicOption,
ApplicationCommandOptionType,
ApplicationCommandType,
InteractionResponseType,
Expand Down Expand Up @@ -34,8 +33,7 @@ export class AutocompleteInteraction extends BaseInteraction<APIApplicationComma

this.options = new AutocompleteOptionsHandler(
client,
(data.data.options ??
[]) as APIApplicationCommandInteractionDataBasicOption[]
data.data.options ?? []
)
}

Expand Down
4 changes: 1 addition & 3 deletions packages/carbon/src/internals/CommandInteraction.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import {
type APIApplicationCommandInteraction,
type APIApplicationCommandInteractionDataBasicOption,
ApplicationCommandType,
InteractionType
} from "discord-api-types/v10"
Expand Down Expand Up @@ -32,8 +31,7 @@ export class CommandInteraction extends BaseInteraction<APIApplicationCommandInt
this.options = new OptionsHandler(
client,
data.data.type === ApplicationCommandType.ChatInput
? ((data.data.options ??
[]) as APIApplicationCommandInteractionDataBasicOption[])
? (data.data.options ?? [])
: []
)
}
Expand Down
22 changes: 20 additions & 2 deletions packages/carbon/src/internals/OptionsHandler.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import {
type APIApplicationCommandInteractionDataBasicOption,
type APIApplicationCommandInteractionDataOption,
type APIChannel,
ApplicationCommandOptionType,
Routes
Expand All @@ -25,10 +26,27 @@ export class OptionsHandler extends Base {

constructor(
client: Client,
options: APIApplicationCommandInteractionDataBasicOption[]
options: APIApplicationCommandInteractionDataOption[]
) {
super(client)
this.raw = options
this.raw = []
for (const option of options) {
if (option.type === ApplicationCommandOptionType.Subcommand) {
for (const subOption of option.options ?? []) {
this.raw.push(subOption)
}
} else if (option.type === ApplicationCommandOptionType.SubcommandGroup) {
for (const subOption of option.options ?? []) {
if (subOption.options) {
for (const subSubOption of subOption.options ?? []) {
this.raw.push(subSubOption)
}
}
}
} else {
this.raw.push(option)
}
}
}

/**
Expand Down

0 comments on commit b29eefd

Please sign in to comment.