Command, Subcommand and Subcommand goup

Comments

2 comments

  • ABDRAHIM abdrahim

    Adaf3a

    0
  • Gregory Chavez

    Hello, valgul 

     

    To organize Discord commands using subcommands and subcommand groups:

    Create Subcommands:
    JavaScript

    const command = new SlashCommandBuilder()
       .setName('ai')
       .setDescription('AI module commands')
       .addSubcommand(subcommand => subcommand.setName('command1').setDescription('Description for command1'))
       .addSubcommand(subcommand => subcommand.setName('command2').setDescription('Description for command2'));
     

    Check Permissions:
    JavaScript

    client.on('interactionCreate', async interaction => {
       if (!interaction.isCommand()) return;
       const { commandName, options } = interaction;
       if (commandName === 'ai') {
           const subcommand = options.getSubcommand();
           if (subcommand === 'command1' && !interaction.member.permissions.has('ADMINISTRATOR')) {
               return interaction.reply('You do not have permission to use this command.');
           }
           // Handle subcommands here
       }
    });

    This keeps your commands organized and allows for permission checks. 

     

    Best  Regard,
    Gregory Chavez
    DollarTreeCompass

    0

Please sign in to leave a comment.