Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: correctly get options of subcommands and subcommandgroups #126

Merged
merged 1 commit into from
Sep 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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