handling - TanzaniteBot/discord-akairo GitHub Wiki
You can categorize a module with the category
option.
import { Command } from "discord-akairo";
import { Message } from "discord.js";
export default class PingCommand extends Command {
constructor() {
super("ping", {
aliases: ["ping"],
category: "stuff"
});
}
exec(message: Message): Promise<Message> {
return message.reply("Pong!");
}
}
A new category will be created on the handler with the ID of stuff
.
By default, all modules are in the default
category.
Everything in Akairo is a module, and all modules are loaded by handlers.
With that said, this means you can add, remove, or reload modules while the bot is running!
Here is a basic command that reloads the inputted ID:
import { Command } from "discord-akairo";
import { Message } from "discord.js";
export default class ReloadCommand extends Command {
constructor() {
super("reload", {
aliases: ["reload"],
args: [
{
id: "commandID"
}
],
ownerOnly: true,
category: "owner"
});
}
exec(message: Message, args: { commandID: string }) {
// `this` refers to the command object.
this.handler.reload(args.commandID);
return message.reply(`Reloaded command ${args.commandID}!`);
}
}
Ways you can reload a module includes:
- Individually:
<AkairoHandler>.reload(moduleID)
<AkairoModule>.reload()
- Many at once:
<AkairoHandler>.reloadAll()
<Category>.reloadAll()
For removing, simply change all those reload
to remove
.
To add a new module, you can use the load
method.
With load
, you will need to specify a full filepath or a module class.
If you load with a class, note that those cannot be reloaded.