discord.js discord-akairo reload command that works on catergories as well as modules (commands) and has error handling!
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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