index.jsconstconfig={"commands": {"directory": "/path/to/commands",//path to commands folder},"bot": {"token": "bot_token_here"}}constDiscord=require('discord.js');constclient=newDiscord.Client();constSlash=require('da-slash');constslash=newSlash.Client(client,config);client.once('ready',()=>{//updates Commandsslash.postCommands();})//emitted when a slash command is detectedclient.ws.on('INTERACTION_CREATE',asyncrequest=>{constinteraction=newSlash.Interaction(client,request);//finds the matching slash command and executes itslash.matchCommand(interaction);})client.login(config.bot.token);
Creating Commands
A file for each command. All files should be contained in one folder or if files are separated by folders, all command folders should be under one command folder.
commandOne.jsconstSlash=require('da-slash');module.exports=newSlash.GlobalCommand({name: 'echo',description: 'sends a message',permissions: ["SEND_MESSAGES"],options: [{"name": "content","description": "message the bot will send","type": 3// Type 3 is string}],execute(interaction){// access discord.Client() through interaction.clientconstclient=interaction.client;// access the data related to the slash command emittedconstrequest=interaction.request;// access the arguments passedconstcontent=request.data.options.find(arg=>arg.name==="content").value;// sends message containing the argumentinteraction.sendMessage(content);}})
commandTwo.jsconstSlash=require('da-slash');module.exports=newSlash.GuildCommand({name: 'hello',description: 'sends a hello message',guilds: ["GuildIdHere"],permissions: ["SEND_MESSAGES"],execute(interaction){interaction.sendMessage("hello");}})
Current Modifications
// Delete global and guild commandsslash.deleteCommands(['613425648685547541','197038439483310086'],true);// Get subcategory commands (assumes there's a utilities folder in your commands directory)slash.commands('utilities');