This event handles the creation execution of the slash commands, using the built-in slash command executing from the slash properties of a command file and also using the built-in client.commands Collection object. We will also display the slash command Id, incase you decide to delete it a server for some reason.
module.exports = { name:'interactionCreate', //discord.js event name async execute(interaction, client) { // execution of slash command //gets the user permissions levelconst level =client.getPermissionsLevel({ author: interaction.user, channel: interaction.channel, guild: interaction.guild, guildMember: interaction.member, }); // check if its a command then proceedif (!interaction.isChatInputCommand()) return; // destructure and get the command name and idconst { commandName, commandId } = interaction; // get the command fileconst cmd =client.commands.get(commandName); // log who call the slash command and the id (id is use for deletion) console.log(`${commandName}`, `${interaction.user.tag}`, `SLASH CMD`);console.log(commandId,'ID','SLASH CMD'); // execute the slash command and response of the slash commandtry {returncmd.interactionReply(interaction, client, level); } catch (e) {console.log("interaction execution failed", e); }``` },};