📄
Discord Features Handler Docs
  • discord-features-handler documentation
  • Getting Started
    • Quick Start
    • Environment Variables
    • DiscordFeaturesHandler Setup
  • Layout
    • Folder Structure
    • Setting up Commands
      • Setting up Slash Commands
      • Setting up other interactions
    • Setting up Events
  • Built-in
    • Disabling Built-in Commands and Events
    • Built-in Functions
    • Built-in config.js file
    • Built-in Customizable Commands
      • Built-in Help Command
      • Built-in Reload Command
    • Built-in Customizable Events
      • Built-in MessageCreate Event
      • Built-in interactionCreate Event
  • References
    • Roadmap
    • ChangeLog
Powered by GitBook
On this page
  1. Built-in
  2. Built-in Customizable Commands

Built-in Reload Command

This is the built-in reload command, that will reload your command files for you so you do not need to restart or reboot your bot for the change of your the current running command file to go into effect.

However if you just uploaded the file then you need to restart your bot.

const fs = require("fs");
const path = require("path");
const absolute = path.resolve();
module.exports = {
  name: "reload",
  description: "Reload a command!",
  aliases: [""],
  guildOnly: false,
  permissions: 8,
  minArgs: 1,
  maxArgs: 1,
  usage: "<command name>",
  async execute(message, args, client) {
    const commandName = args[0];
    let command;

    if (client.commands.has(commandName)) {
      command = client.commands.get(commandName);
    } else if (client.aliases.has(commandName)) {
      command = client.commands.get(client.aliases.get(commandName));
    }

    if (!command)
      return message.channel.send(
        `The command \`${commandName}\` doesnt seem to exist, nor is it an alias. Try again!`
      );

    const fileName = command.name;
    const commandFolders = fs.readdirSync(absolute + "/commands");

    const folderName = commandFolders
      .map((folder) => {
        const filePathJS = path.join(
          client.dfhSettings.mainDirectory,
          client.dfhSettings.commandDir,
          folder,
          fileName + ".js"
        );
        const filePathTS = path.join(
          client.dfhSettings.mainDirectory,
          client.dfhSettings.commandDir,
          folder,
          fileName + ".ts"
        );
        if (fs.existsSync(filePathJS) || fs.existsSync(filePathTS)) {
          return folder;
        }
      })
      .join("");
    let response = await client.unloadCommand(fileName, folderName);
    if (response) return message.reply(`Error Unloading: ${response}`);

    response = client.loadCommand({
      file: fileName,
      folder: folderName,
      loadingMsg: true,
    });
    if (response) return message.reply(`Error Loading: ${response}`);
    message.reply(`The command \`${commandName}\` has been reloaded`);
  },
};

Check back later for update!

PreviousBuilt-in Help CommandNextBuilt-in Customizable Events

Last updated 1 year ago