Slash Command Question

const { SlashCommandBuilder } = require('@discordjs/builders');

module.exports = {
  name: 'data',
  description: 'Commands related to user data.',

  subcommands: [
    new SlashCommandBuilder()
      .setName('create')
      .setDescription('Creates a new user account.'),
    new SlashCommandBuilder()
      .setName('delete')
      .setDescription('Deletes all data of the specified user.')
      .addStringOption(option => option.setName('user_id').setDescription('The ID of the user to delete data for.').setRequired(true)),
    new SlashCommandBuilder()
      .setName('showraw')
      .setDescription('Shows all data of a specified user.')
      .addStringOption(option => option.setName('user_id').setDescription('The ID of the user to show data for.').setRequired(true)),

  ],

async function dataCommand(client, interaction) {
  // Get the subcommand name
  const subcommandName = interaction.options.getSubcommand();

  // Check if the subcommand name is valid
  if (!subcommandName) {
    // The user did not specify a subcommand
    await interaction.reply('You need to specify a subcommand.');
    return;
  }

  // Call the appropriate function based on the subcommand name
  switch (subcommandName) {
    case 'create':
      await create(client, interaction);
      break;

    case 'delete':
      await deleteUserData(client, interaction);
      break;

    case 'showraw':
      await showraw(client, interaction);
      break;
  }
}


I strongly believe i did something wrong related to SlashCommandBuilder but dunno how to fix

So I want to create a slash command like
/data <option_require>
option is create, delete, showraw. when select
delete or showraw
//
 <option2>
will appear where i can input userid or something
Was this page helpful?
Slash Command Question - discord.js - Imagine ❄