-
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: interaction#options should never be null (#108)
* feat: always have options handler * add changeset
- Loading branch information
1 parent
ec43a73
commit d76feb7
Showing
7 changed files
with
31 additions
and
58 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"@buape/carbon": patch | ||
--- | ||
|
||
fix: interaction#options should never be null |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,53 +1,40 @@ | ||
import { | ||
type APIApplicationCommandInteraction, | ||
type APIApplicationCommandInteractionDataBasicOption, | ||
ApplicationCommandOptionType, | ||
ApplicationCommandType, | ||
InteractionType | ||
} from "discord-api-types/v10" | ||
import type { BaseCommand } from "../abstracts/BaseCommand.js" | ||
import { | ||
BaseInteraction, | ||
type InteractionDefaults | ||
} from "../abstracts/BaseInteraction.js" | ||
import type { Client } from "../classes/Client.js" | ||
import { Command } from "../classes/Command.js" | ||
import { OptionsHandler } from "./OptionsHandler.js" | ||
// import type { RawOptions } from "./OptionsHandler.js" | ||
|
||
/** | ||
* Represents a command interaction | ||
*/ | ||
export class CommandInteraction extends BaseInteraction<APIApplicationCommandInteraction> { | ||
/** | ||
* This is the options of the commands, parsed from the interaction data. | ||
* It is only available if the command is a {@link Command} class, and the command is a ChatInput command. | ||
* It will not have any options in it if the command is not a ChatInput command. | ||
*/ | ||
options?: OptionsHandler | ||
options: OptionsHandler | ||
constructor( | ||
client: Client, | ||
data: APIApplicationCommandInteraction, | ||
defaults: InteractionDefaults, | ||
command?: BaseCommand | ||
defaults: InteractionDefaults | ||
) { | ||
super(client, data, defaults) | ||
if (data.type !== InteractionType.ApplicationCommand) { | ||
throw new Error("Invalid interaction type was used to create this class") | ||
} | ||
if ( | ||
command instanceof Command && | ||
data.data.type === ApplicationCommandType.ChatInput && | ||
!data.data.options?.find( | ||
(x) => | ||
x.type === ApplicationCommandOptionType.Subcommand || | ||
x.type === ApplicationCommandOptionType.SubcommandGroup | ||
) | ||
) { | ||
this.options = new OptionsHandler( | ||
client, | ||
(data.data.options ?? | ||
[]) as APIApplicationCommandInteractionDataBasicOption[] | ||
) | ||
} | ||
this.options = new OptionsHandler( | ||
client, | ||
data.data.type === ApplicationCommandType.ChatInput | ||
? ((data.data.options ?? | ||
[]) as APIApplicationCommandInteractionDataBasicOption[]) | ||
: [] | ||
) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters