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: use optional chaining in ApplicationCommand's subCommand[group] … #281

Merged
merged 3 commits into from
Jan 1, 2022
Merged
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
10 changes: 6 additions & 4 deletions src/structures/applicationCommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,12 +70,14 @@ export class ApplicationCommandInteraction extends Interaction {

/** Gets sub command name from options */
get subCommand(): string | undefined {
if (this.data.options[0].type === ApplicationCommandOptionType.SUB_COMMAND)
if (
this.data.options?.[0]?.type === ApplicationCommandOptionType.SUB_COMMAND
)
return this.data.options[0].name
else if (
this.data.options[0].type ===
this.data.options?.[0]?.type ===
ApplicationCommandOptionType.SUB_COMMAND_GROUP &&
this.data.options[0].options?.[0].type ===
this.data.options?.[0]?.options?.[0]?.type ===
ApplicationCommandOptionType.SUB_COMMAND
)
return this.data.options[0].options[0].name
Expand All @@ -84,7 +86,7 @@ export class ApplicationCommandInteraction extends Interaction {
/** Gets sub command group name from options */
get subCommandGroup(): string | undefined {
if (
this.data.options[0].type ===
this.data.options?.[0]?.type ===
ApplicationCommandOptionType.SUB_COMMAND_GROUP
)
return this.data.options[0].name
Expand Down