EcoBot/node_modules/load-slash-commands
2021-11-23 00:53:12 +01:00
..
index.js Fix stuff up and add .env to .gitignore 2021-11-23 00:53:12 +01:00
package.json Fix stuff up and add .env to .gitignore 2021-11-23 00:53:12 +01:00
README.md Fix stuff up and add .env to .gitignore 2021-11-23 00:53:12 +01:00

load-slash-commands

This module is a module for quickly loading commands from main file without needing any mess in the root directory.

Usage

Using this module is pretty simple, here is an example using Discord.JS:

const registerCommands = require("register-slash-commands");
const {Client, Intents} = require("discord.js");
const client = new Client({intents: [Intents.flags.GUILDS]});

const commands = [
  {
    name: "ping",
    description: "Sends the client's WebSocket latency."
  }
];
client.on("ready", () => {
  registerCommands(client, commands);
});

client.on("interactionCreate", (int) => {
  if(!int.isCommand()) return;
  if(int.commandName == "ping"){
    int.reply(`My latency is ${client.ws.ping} ms.`);
  }
});

Or if you want to use guild specific commands:

const registerCommands = require("register-slash-commands");
const {Client, Intents} = require("discord.js");
const client = new Client({intents: [Intents.flags.GUILDS]});
const guildId = "846496831533088768";

const commands = [
  {
    name: "ping",
    description: "Sends the client's WebSocket latency."
  }
];
client.on("ready", () => {
  registerCommands(client, commands, guildId);
});

client.on("interactionCreate", (int) => {
  if(!int.isCommand()) return;
  if(int.commandName == "ping"){
    int.reply(`My latency is ${client.ws.ping} ms.`);
  }
});