Looking for a good way to organize subcommand groups

I am trying to organize subcommand groups and their subcommands, but I feel like there is a better way of doing this and I am doing it wrong. Is using .options.getSubcommand() and then calling the required function a good way? Here is my code
const { SlashCommandBuilder } = require('discord.js');
const subTest = require('../../utils/subTest');

module.exports = {
data: new SlashCommandBuilder()
.setName('cmd')
.setDescription('Subcommand test')
.addSubcommandGroup((subcommandGroup) =>
subcommandGroup
.setName('group1')
.setDescription('group 1')
.addSubcommand((subcommand) =>
subcommand.setName('sub1-1').setDescription('sub 1-1')
)
.addSubcommand((subcommand) =>
subcommand.setName('sub1-2').setDescription('sub 1-2')
)
)
.addSubcommandGroup((subcommandGroup) =>
subcommandGroup
.setName('group2')
.setDescription('group 2')
.addSubcommand((subcommand) =>
subcommand.setName('sub2-1').setDescription('sub 2-1')
)
.addSubcommand((subcommand) =>
subcommand.setName('sub2-2').setDescription('sub 2-1')
)
)
.addSubcommand((subcommand) =>
subcommand.setName('outside').setDescription('outside sub')
),

async execute(client, interaction) {
console.log(interaction.options.getSubcommand());
if (interaction.options.getSubcommand() === 'sub1-1') {
await interaction.reply('sub1-2');

// Call required function here
subTest();
} else {
await interaction.reply('other subcomand');
}
},
};
const { SlashCommandBuilder } = require('discord.js');
const subTest = require('../../utils/subTest');

module.exports = {
data: new SlashCommandBuilder()
.setName('cmd')
.setDescription('Subcommand test')
.addSubcommandGroup((subcommandGroup) =>
subcommandGroup
.setName('group1')
.setDescription('group 1')
.addSubcommand((subcommand) =>
subcommand.setName('sub1-1').setDescription('sub 1-1')
)
.addSubcommand((subcommand) =>
subcommand.setName('sub1-2').setDescription('sub 1-2')
)
)
.addSubcommandGroup((subcommandGroup) =>
subcommandGroup
.setName('group2')
.setDescription('group 2')
.addSubcommand((subcommand) =>
subcommand.setName('sub2-1').setDescription('sub 2-1')
)
.addSubcommand((subcommand) =>
subcommand.setName('sub2-2').setDescription('sub 2-1')
)
)
.addSubcommand((subcommand) =>
subcommand.setName('outside').setDescription('outside sub')
),

async execute(client, interaction) {
console.log(interaction.options.getSubcommand());
if (interaction.options.getSubcommand() === 'sub1-1') {
await interaction.reply('sub1-2');

// Call required function here
subTest();
} else {
await interaction.reply('other subcomand');
}
},
};
No description
2 Replies
d.js toolkit
d.js toolkit7mo ago
- What's your exact discord.js npm list discord.js and node node -v version? - Not a discord.js issue? Check out #other-js-ts. - Consider reading #how-to-get-help to improve your question! - Explain what exactly your issue is. - Post the full error stack trace, not just the top part! - Show your code! - Issue solved? Press the button!
Unknown User
Unknown User7mo ago
Message Not Public
Sign In & Join Server To View
Want results from more Discord servers?
Add your server