Giter Site home page Giter Site logo

ming-suhi / da-slash Goto Github PK

View Code? Open in Web Editor NEW
5.0 5.0 1.0 41 KB

Creating and managing Discord Slash Commands made simple

License: MIT License

JavaScript 100.00%
discord discord-command discord-framework discord-interactions discord-js discord-slash discord-slash-commands slash-commands

da-slash's People

Contributors

ming-suhi avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

fasko-web

da-slash's Issues

[commands() & findCommand()] [Subcategory Require functions grab from da-slash src node_module location]

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/'

commands() & findCommand(command_name)

// ./bot.js

config = {
  commands: {
    directory: './commands',
    subcategories: 'true'
  }
}

// ./node_modules/da-slash/src/client.js

9  | async commands() {
21 |   let command = require(`${dir}/${folder}/${file}`);

37 | async findCommand(command_name) {
49 |   let command = require(`${dir}/${subfolderRef}/${file}`);

The error being produced
UnhandledPromiseRejectionWarning: Error: Cannot find module './commands/subcategory/command.js'

Expected behavior
Expected to find existing module at specified location.

Additional context
Adding require.main.require(); to line 21 and 49 in client.js fixed the issue for me

Delete All Commands Function

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.

Function

async deleteCommands(guild_ids = false, del_global = false) {
  let deletedCommands = new Array();
  if (guild_ids) {
    let postedGuildCommands = new Array();
    for (let guild_id of guild_ids) {
      const guildCommands = await this.client.api.applications(this.client.user.id).guilds(guild_id).commands.get();
      for (let i = 0; i < guildCommands.length; i++) {
        this.client.api.applications(this.client.user.id).guilds(guild_id).commands(guildCommands[i].id).delete();
      }
      postedGuildCommands.push({ guild: guild_id, commands: guildCommands });
    }
    deletedCommands.push({ guilds: postedGuildCommands });
  }
  if (del_global) {
    const postedGlobalCommands = await this.client.api.applications(this.client.user.id).commands.get();
    for (let i = 0; i < postedGlobalCommands.length; i++) {
      this.client.api.applications(this.client.user.id).commands(postedGlobalCommands[i].id).delete();
    }
    deletedCommands.push({ global: postedGlobalCommands });
  }
  return deletedCommands;
}

Usage

client.on('ready', async () => {
  await slash.deleteCommands(['613425648685547541','197038439483310086'], true);
  slash.postCommands();
});

Originally posted by @fasko-web in #8

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.