Skip to content

Instantly share code, notes, and snippets.

@edazpotato
Last active Apr 24, 2021
Embed
What would you like to do?
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