Adding SubCommand to commands.

I'm using this snippet to load my slash commands.
// Function to register commands from the "./commands" directory
const registerCommands = async () => {
const commandFiles = await fsPromises.readdir("./commands");
for (const file of commandFiles) {
const command = require(`./commands/${file}`);
if (command && command.name) {
client.commands.set(command.name, command);
handlers.logHandler.log(`Registered Command ${command.name}`, 1);
} else {
handlers.logHandler.log(
`Command ${file} is missing data or name property. Skipping.`,
2
);
}
}
};
// Function to register commands from the "./commands" directory
const registerCommands = async () => {
const commandFiles = await fsPromises.readdir("./commands");
for (const file of commandFiles) {
const command = require(`./commands/${file}`);
if (command && command.name) {
client.commands.set(command.name, command);
handlers.logHandler.log(`Registered Command ${command.name}`, 1);
} else {
handlers.logHandler.log(
`Command ${file} is missing data or name property. Skipping.`,
2
);
}
}
};
Here is an example of a command in that ./command file
const handlers = require("../handlerLoader.js");
const { client } = require("../index");

module.exports = {
name: "embed",
description:
"Send a specific embed to the channel you execute this command in.",
async execute(interaction) {
try {
const guild = await client.guilds.fetch(interaction.guild.id);
const member = await guild.members.fetch(interaction.user.id);

const isAdmin = member.permissions.has(PermissionFlagsBits.Administrator);
console.log(isAdmin)
} catch (error) {
console.error(`Error in hasAdminPermissions: ${error}`);
return false;
}
}
};
const handlers = require("../handlerLoader.js");
const { client } = require("../index");

module.exports = {
name: "embed",
description:
"Send a specific embed to the channel you execute this command in.",
async execute(interaction) {
try {
const guild = await client.guilds.fetch(interaction.guild.id);
const member = await guild.members.fetch(interaction.user.id);

const isAdmin = member.permissions.has(PermissionFlagsBits.Administrator);
console.log(isAdmin)
} catch (error) {
console.error(`Error in hasAdminPermissions: ${error}`);
return false;
}
}
};
How would i add a SubCommand and other arguments to that command? I can't figure it out 💜 Also feel free to ping me! :D
4 Replies
d.js toolkit
d.js toolkit•6mo 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
Kiɾʌ Kenjiɾø
.addUserOption(option =>
option.setName('target')
.setDescription('Ping the user')
.setRequired(false))
.addUserOption(option =>
option.setName('target')
.setDescription('Ping the user')
.setRequired(false))
I know you can do something along the lines of that but not too sure how that? Converts into the way im doing it :0
d.js docs
d.js docs•6mo ago
discord Application Commands - Application Command Object options? read more
Kiɾʌ Kenjiɾø
Yewah it acts the same way, AH yeah got it i can just add it as option type then use SUB_COMMAND Mint mint!! Thanks Qj! <3 SICK!!! :D yeah i think i had the object wrong that was it