index.jsconstconfig={"commands": {"directory": "/path/to/commands",//path to commands folder"subcategories": "false"//if commands are divided by folders change to "true"},"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");}})
While da-slash does provide a delete function, it's only setup for commands it created and that still exists.
So if I delete a command's file, I can no longer call it up and delete it, I'd have to recreate the command with the same name, then delete it.
Here's a deleteCommands function that could be added to client.js, allowing you to delete all commands initialized by the bot, either globally or per guild via await slash.deleteCommands(guild_ids, del_global). guild_ids being an array of guild ids. del_global being a boolean to delete global commands or not.
Describe the bug
When using the categories option it requires command files from da-slash's node_modules directory, instead of the location the module is required at. IE. Commands are in './commands/folders/' but it's looking for them in './node_modules/da-slash/src/commands/folders/'