How do I make subcommands?

So I am trying from to create two subcommands under info. One: info user and other: info server. I am not very sure on how to give different response to each subcommand because if I keep interaction.reply() in execute function I am getting same reply for both the sub commands. What function do I use to fetch which sub command has been used?? My code:
const { SlashCommandBuilder } = require("discord.js");

module.exports = {
cooldown: 5,
data: new SlashCommandBuilder()
.setName("info")
.setDescription("Get info about a user or a server!")
.addSubcommand((subcommand) =>
subcommand
.setName("user")
.setDescription("Info about a user")
.addUserOption((option) =>
option.setName("target").setDescription("The user")
)
)
.addSubcommand((subcommand) =>
subcommand.setName("server").setDescription("Info about the server")
),
async execute(interaction) {

},
};
const { SlashCommandBuilder } = require("discord.js");

module.exports = {
cooldown: 5,
data: new SlashCommandBuilder()
.setName("info")
.setDescription("Get info about a user or a server!")
.addSubcommand((subcommand) =>
subcommand
.setName("user")
.setDescription("Info about a user")
.addUserOption((option) =>
option.setName("target").setDescription("The user")
)
)
.addSubcommand((subcommand) =>
subcommand.setName("server").setDescription("Info about the server")
),
async execute(interaction) {

},
};
6 Replies
d.js toolkit
d.js toolkit•9mo 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! - ✅ Marked as resolved by OP
!Arnavᴰᴱⱽ
Discord.js version is 14.14.1 Node version in 20.11.0
d.js docs
d.js docs•9mo ago
guide Slash Commands: Advanced command creation - Subcommands read more
!Arnavᴰᴱⱽ
I made mine from the guide only
chewie
chewie•9mo ago
discord.js Guide
Imagine a guide... that explores the many possibilities for your discord.js bot.
!Arnavᴰᴱⱽ
oo ill try that ty
Want results from more Discord servers?
Add your server