Subcommands show up as individual commands

Hey! I'm having some trouble with commands and subcommands. I've already implemented the code for /count create and /count set, but whenever the bot is deployed, the slash commands being shown are just /create and /set. Here is the commands code.
const { SlashCommandBuilder } = require("discord.js");
const Count = require("../../lib/database/models/count.model.js");
const { connectToDatabase } = require("../../lib/database/index.js");

module.exports = {
data: new SlashCommandBuilder()
.setName("count")
.setDescription("Count Commands")
.addSubcommand((subcommand) =>
subcommand
.setName("create")
.setDescription("Creates a new count")
.addStringOption((option) =>
option.setName("name").setDescription("Count Name").setRequired(true)
)
)
.addSubcommand((subcommand) =>
subcommand
.setName("set")
.setDescription("Set the current count for the sever")
.addStringOption((option) =>
option.setName("id").setDescription("Count ID").setRequired(true)
)
),

async execute(interaction) {

const command = interaction.options.getSubcommand();

switch (command) {

case "create":

try {
await connectToDatabase();
const newCount = await Count.create({
name: interaction.options.getString("name"),
value: 0,
creator: interaction.member.id,
createdAt: Date.now(),
});
await interaction.reply(
`Sucessfully created count with name ${interaction.options.getString(
"name"
)} and ID ${newCount._id}!`
);
console.log(
`New Count Created in DB ${interaction.options.getString("name")}`
);
console.log(JSON.parse(JSON.stringify(newCount)));
} catch (error) {
console.log(error);
await interaction.reply(
`Error creating count in database. Contact @jordan for help.`
);
}
break;

case "set":

try {
await connectToDatabase();
await interaction.reply(
`Setting count to ${interaction.options.getString("ID")}`
);
console.log(
`Sever Count Set to ${interaction.options.getString("ID")} for ${
interaction.guild.name
}`
);
} catch (error) {
console.log(error);
await interaction.reply(
`Error creating count in database. Contact @jordan for help.`
);
}
break;

default:

await interaction.reply(`Invalid Subcommand!`);
break;
}
},
};
const { SlashCommandBuilder } = require("discord.js");
const Count = require("../../lib/database/models/count.model.js");
const { connectToDatabase } = require("../../lib/database/index.js");

module.exports = {
data: new SlashCommandBuilder()
.setName("count")
.setDescription("Count Commands")
.addSubcommand((subcommand) =>
subcommand
.setName("create")
.setDescription("Creates a new count")
.addStringOption((option) =>
option.setName("name").setDescription("Count Name").setRequired(true)
)
)
.addSubcommand((subcommand) =>
subcommand
.setName("set")
.setDescription("Set the current count for the sever")
.addStringOption((option) =>
option.setName("id").setDescription("Count ID").setRequired(true)
)
),

async execute(interaction) {

const command = interaction.options.getSubcommand();

switch (command) {

case "create":

try {
await connectToDatabase();
const newCount = await Count.create({
name: interaction.options.getString("name"),
value: 0,
creator: interaction.member.id,
createdAt: Date.now(),
});
await interaction.reply(
`Sucessfully created count with name ${interaction.options.getString(
"name"
)} and ID ${newCount._id}!`
);
console.log(
`New Count Created in DB ${interaction.options.getString("name")}`
);
console.log(JSON.parse(JSON.stringify(newCount)));
} catch (error) {
console.log(error);
await interaction.reply(
`Error creating count in database. Contact @jordan for help.`
);
}
break;

case "set":

try {
await connectToDatabase();
await interaction.reply(
`Setting count to ${interaction.options.getString("ID")}`
);
console.log(
`Sever Count Set to ${interaction.options.getString("ID")} for ${
interaction.guild.name
}`
);
} catch (error) {
console.log(error);
await interaction.reply(
`Error creating count in database. Contact @jordan for help.`
);
}
break;

default:

await interaction.reply(`Invalid Subcommand!`);
break;
}
},
};
Not too sure why it's not picking up its a subcommand, but if anyone has had a similar issue, any help is appreciated!
2 Replies
d.js toolkit
d.js toolkit12mo 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
jordan
jordanOP12mo ago
Discord.js Version: [email protected] Node: v20.6.0 Solved for anyone who has the same issue - Restarting discord seems to fix it.
Want results from more Discord servers?
Add your server