Skip to main content

Command Loader

In this guide, we will explain how to get started with command handlers, create multiple commands in one file, and handle events.

Why Should You Use a Loader?

Why should you use a command handler? Storing your commands in a single file may seem fine at first, but as the number of commands grows, it becomes difficult to find and update them. That's why you should use a command handler to maintain order in your main file and rid yourself of clutter.

Main File

  • In the LoadCommands class constructor, it is mandatory to specify your instance of the AoiClient class. In the loadCommands method, the first argument is the path to the folder, and the second argument is responsible for console output.
  • For easier use or tracking of variables in the library, you can utilize the loadVariables method, which is built into the LoadCommands class.
const { LoadCommands } = require("aoitelegram");

const loader = new LoadCommands(bot)
loader.loadCommands("./command/", true);
loader.loadVariables("./variables/", true);

Example

One Command in a File

export default {
name: "ping",
code: `$replyMessage[Bot ping: $ping ms]`,
};

Multiple Commands in a File

export default [
{
name: "ping",
code: `$replyMessage[Bot ping: $ping ms]`,
},
{
name: "pong",
code: `$replyMessage[ping 🏓]`,
},
];

Events

export default [
{
name: "count",
code: `$replyMessage[Count value: $getVar[count]]`,
},
{
type: "message",
code: `$setVar[count;$message[1]]`,
},
];

Variables

export default {
variables: {
sempai: 10,
string: "Hello, world!",
aoijs: true,
webapp: false,
mz: [],
},
tables: ["main"],
};