As Commands are now classes, you can now easily create "templates", templates are just children of the Command
class with added properties & methods for your different cases.
You can create templates just by creating abstract children classes of the Command
class and use them in your code, you don't need to register them or anything.
There are 2 defaults templates.
SlowCommand
: AddsstartWait(message)
andstopWait(message)
methods that react and removes the reaction from the "wait" emoji which is defined by thewaitEmoji
property, and you can overwrite it to have a custom emoji. It is 🕰 by default.ImageCommand
: AddssendLocalImage(options)
for sending an image from a local path andsendImageEmbed(options)
for sending an embed containing an image, both have also options for description and the channel where to send the message.
{% code title="MyCommand.js" %}
const mySlowTask = require('./mySlowTask.js');
module.exports = class MyCommand extends SlowCommand {
name = 'test';
async run(ctx) {
const message = ctx.send("Please wait a bit while I'm performing the task.");
await this.startWait(message);
await ctx.deleteMessage();
const result = await mySlowTask();
await this.stopWait(message);
await message.edit(result);
}
}
{% endcode %}