Skip to content
This repository has been archived by the owner on Feb 9, 2021. It is now read-only.

Releases: ming-suhi/da-slash

v1.3.6

22 Jan 15:12
Compare
Choose a tag to compare

Release Notes

Edited Client Class

  1. Removed deleteCommand() method
    To delete a command delete it from GuildCommand Class or GlobalCommand Class
  2. Edited postCommands() method
    Instead of getting command datas and posting it, this get all commands and calls the command post() function

Command Class Notes

  1. As a result of the postCommand() method of the Client Class being changed, don't use Command Class in creating commands, instead use GuildCommand Class or GlobalCommand Class

Added Classes

  1. GlobalCommand extends Command
  2. GuildCommand extends Command

v1.3.3

17 Jan 07:16
Compare
Choose a tag to compare

Release Notes

Methods Update

  1. Methods now return promises

Edited Client Class

  1. commands property removed
    access commands through .commands() method
  2. added .commands() method
  3. edited deleteCommand() method
    removed guild constructor
  4. postCommands() method Update
    now logs Error instead of string
  5. added .findCommand() method

Edited Interaction Class

  1. added .author() method
  2. added .guild() method
  3. added .channel() method
  4. added .bot() method

v1.3.2

27 Dec 13:03
Compare
Choose a tag to compare

Release Notes

Removed Client.getCommands() and made property commands

usage

//previous version
const slash = new Slash.Client(client, config);
console.log(slash.getCommands());

//new version
const slash = new Slash.Client(client, config);
console.log(slash.commands);

Changed Client.deleteCommand()

changed constructor guildObject to guildID

usage

//previous version
const slash = new Slash.Client(client, config);
let guild = client.guilds.cache.get(guild_id_here);
slash.deleteCommand(guild, commandID);

//new version
const slash = new Slash.Client(client, config);
slash.deleteCommand(guildID, commandID);

v1.3.1

25 Dec 12:32
Compare
Choose a tag to compare

Release Notes

Added New Class | Interaction

Discord client and Websocket Interaction now found in Interaction Class. Discord client and Websocket Interaction will not be passed down to execute function of Slash.Command, instead the instance of Interaction will be passed down instead. Discord client should be accessed through Interaction.client, and websocket interaction through Interaction.request.

usage

commandThree.js
module.exports = new Slash.Command({
  name: 'invisible',
  description: 'sends a hello world message visible to user only',
  permissions: ["SEND_MESSAGES"],
  execute(interaction) { // instead of execute(client, interaction)
  
    interaction.sendEphemeral("Hello World")
    
  }
})
Instead of passing web socket interaction to the method matchCommand, pass down the instance of Interaction.

usage

index.js

// previous version
client.ws.on('INTERACTION_CREATE', async request => {
  slash.matchCommand(request);
})

// new version
client.ws.on('INTERACTION_CREATE', async request => {
  const interaction = new Slash.Interaction(client, request);
  slash.matchCommand(interaction);
})

Slash Interaction

constructor

new Slash.Interaction(discord_client, interaction)

methods

.sendMessage(content) - sends a message
.sendEphemeral(content) - sends an ephemeral(user-visible only) message
.sendEmbed(discord_embed) - sends an embed

usage

commandTwo.js
module.exports = new Slash.Command({
  name: 'invisible',
  description: 'sends a hello world message visible to user only',
  permissions: ["SEND_MESSAGES"],
  execute(interaction) {
  
    interaction.sendEphemeral("Hello World")
    
  }
})

v1.2.1

25 Dec 07:17
Compare
Choose a tag to compare

Release Notes

Added error handler for DiscordAPIError: Missing Access

Now Informs users of guilds not affected by slash commands

v1.2.0

25 Dec 04:33
Compare
Choose a tag to compare

Release Notes

Edited Client methods

Removed discord_client constructor from all methods

v1.0.0

25 Dec 04:15
Compare
Choose a tag to compare

Slash Client

constructor

new Slash.Client(discord_client, config);

methods

.getCommands() - Returns a map of commands
.postCommands(discord_client) - Posts/updates all commands
.deleteCommand(discord_client, guild, command_id_here) - Deletes chosen command from a certain guild
.matchCommand(discord_client, interaction) - runs through all commands and executes match

usage

index.js
const config = {
"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"
  }    
}

const Discord = require('discord.js');
const client = new Discord.Client();
const Slash = require('da-slash');
const slash = new Slash.Client(client, config);

client.once('ready', () => {
  //updates Commands
  slash.postCommands(client);
  
  //deletes Command
  let guild = client.guilds.cache.get(guild_id_here);
  slash.deleteCommand(client, guild, command_id_here)
})

//emitted when a slash command is detected
client.ws.on('INTERACTION_CREATE', async interaction => {
  //finds the appropriate slash command and executes it
  slash.matchCommand(client, interaction); 
})

client.login(config.bot.token);

Slash Command

constructor

new Slash.Command(data);

data

name - name of command
description - description of command
permissions - required permissions to execute command
options - options for command
execute - function to be executed, will not be executed if permissions are not met and sends an ephemeral message

usage

commandOne.js
module.exports = new Slash.Command({
  name: 'hello',
  description: 'sends ',
  permissions: ["SEND_MESSAGES"],
  execute(client, interaction) {
  
    // sends "Hello World!"
    client.api.interactions(interaction.id, interaction.token).callback.post({
      data: {
        type: 4,
        data: {
          content: "Hello World!"
        }
      }
    });
    
  }
})