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: slash command handler subcommands keys aren't type-safe #56

Open
neolectron opened this issue Sep 4, 2023 · 0 comments
Open

fix: slash command handler subcommands keys aren't type-safe #56

neolectron opened this issue Sep 4, 2023 · 0 comments
Labels
enhancement New feature or request

Comments

@neolectron
Copy link
Member

Problem

Subcommands keys aren't typechecked.

{
  schema: new SlashCommandBuilder()
    .setName('myCommand')
    .addSubcommand((subcommand) =>
      subcommand.setName('subcommand1').setDescription('do 1'),
    )
    .addSubcommand((subcommand) =>
      subcommand
        .setName('subcommand2')
        .setDescription('do 2'),
    )
    .toJSON(),
  handler: {
    somethingNotLegit: async (interaction) => {},
    anyKeyCanBeHere: async (interaction) => {},
	// ^ ------------ Not legit
  },
}

Solution

Override the type of schema with subcommands strings as const (or check if they aren't in the type already). Then retrieve the subcommands keys with a type helper.

@neolectron neolectron changed the title slash command handler subcommands keys aren't type-safe fix: slash command handler subcommands keys aren't type-safe Sep 4, 2023
@neolectron neolectron added the enhancement New feature or request label Sep 19, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant