In order for slash commands to run when placed inside their respective sub-folders of the command directory, you need to set the object properties for each command based off the non-slash commands and also include slash method and properties shown below.
Usage
Here is a sample slash command example created using the previous ping.js command we created in the last doc page:
const { SlashCommandBuilder } =require("discord.js");// I recommend you define the command name and description here to prevent // retyping them if you decide to have prefix and slash command to call the cmdconstname="ping";constdescription="Ping Pong Command";module.exports= { name, description, aliases: ['p'], guildOnly:true, permissions:0, minArgs:0, usage:'',// defines as slash command using Discord.js SlashCommandBuilder data:newSlashCommandBuilder() .setName(name).setDescription(description),execute(message, args, client) {returnmessage.channel.send({ content:'Pong' }); },asyncinteractionReply(interaction) { // define what the slash command doesawaitinteraction.reply({ content:'Pong!' }); }};
const { SlashCommandBuilder } =require("discord.js");// I recommend you define the command name and description here to prevent // retyping them if you decide to have prefix and slash command to call the cmdconstname="ping";constdescription="Ping Pong Command";module.exports= { name, description, aliases: ['p'], guildOnly:true, permissions:0, minArgs:0, usage:'', data:newSlashCommandBuilder().setName(name).setDescription(description).addUserOption((option) => option.setName("someone").setDescription("Mention Someone").setRequired(true) ),execute(message, args, client) {returnmessage.channel.send('Pong.'); },asyncinteractionReply(interaction) {const { options } = interaction;constuser=awaitoptions.getUser('someone');awaitinteraction.reply({ content:`Hello ${user.username}!` }); }};