Skip to content

Instantly share code, notes, and snippets.

@edazpotato
Last active April 24, 2021 07:15
Show Gist options
  • Save edazpotato/fa3734c791e6776c641d1e5f7c8d95a2 to your computer and use it in GitHub Desktop.
Save edazpotato/fa3734c791e6776c641d1e5f7c8d95a2 to your computer and use it in GitHub Desktop.
discord.js discord-akairo reload command that works on catergories as well as modules (commands) and has error handling!
const { Command } = require("discord-akairo");
class ReloadCommand extends Command {
constructor() {
super("reload", {
aliases: ["reload"],
args: [
{
id: "commandID",
default: "all"
}
],
ownerOnly: true,
category: "owner"
});
}
exec(message, args) {
// `this` refers to the command object.
if (args.commandID == "all") {
this.handler.reloadAll();
return message.util.send(
`Reloaded ${
this.handler.modules.map((m) => m).length
} command(s)!`
);
}
try {
this.handler.reload(args.commandID);
return message.util.send(`Reloaded command ${args.commandID}!`);
} catch {
try {
const category = this.handler.categories
.map((c) => c)
.filter((c) => c == args.commandID)[0];
category.reloadAll();
return message.util.send(
`Reloaded category ${args.commandID}!\nReloaded ${
category.map((m) => m).length
} command(s)!`
);
} catch (e) {
return message.util.send(
`${args.commandID} is not a valid category/command ID!`
);
}
}
}
}
module.exports = ReloadCommand;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment