EcoBot/node_modules/load-slash-commands/README.md

1.4 KiB

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.`);
  }
});