-
Notifications
You must be signed in to change notification settings - Fork 314
Plugin Creation
AstroX10 edited this page Dec 28, 2024
·
1 revision
Commands are registered using the bot
function. It takes two arguments:
- Command Configuration: An object that defines the command's behavior and properties.
- Callback Function: An asynchronous function that contains the logic to execute the command.
Below is an example of a simple ping
command:
import { bot } from '#lib'; // Global import for the bot framework
bot(
{
pattern: 'ping', // Command trigger word
public: true, // true = accessible by everyone, false = restricted to owners/sudo
isGroup: true, // true = command only works in groups
desc: 'Check performance response', // Command description for help menus
type: 'system' // Category of the command (e.g., 'system', 'fun', 'utility')
},
async (message, match) => {
/**
* Command functionality
*/
const start = Date.now();
await message.send('Pong!'); // Sends a reply
const end = Date.now();
await message.send(`Response Time: ${end - start}ms`);
}
);
Property | Type | Description |
---|---|---|
pattern | string | The command's trigger word (e.g., ping) |
public | boolean | true for public commands, false for owner/sudo-only commands |
isGroup | boolean | true if the command works only in groups, otherwise it won't execute |
desc | string | A brief description of the command for help menus or debugging |
type | string | Command category (e.g., system, fun, utility) |
The second parameter is an asynchronous function that:
-
Receives Parameters:
-
message
: The messaging instance for handling replies or events -
match
: Arguments or inputs matched by the command
-
-
Contains Logic: Implement your command's functionality inside this function
Note: The Xstro framework includes built-in error handling, so you don't need to use try-catch
blocks.
Commands can perform various tasks, such as replying to messages, accessing inputs, or interacting with APIs. For instance:
Send a Reply:
await message.send('Hello, World!');
Access Command Arguments:
const input = match || 'default'; // Uses `match` to get user input
Perform Asynchronous Actions:
const data = await fetch('https://api.example.com/data');
const result = await data.json();
await message.send(`Data: ${result.value}`);
bot(
{
pattern: 'echo',
public: true,
isGroup: false, // This command works only in private chats
desc: 'Echoes back your input',
type: 'utility'
},
async (message, match) => {
await message.send(match || 'You didn\'t provide any text!');
}
);
bot(
{
pattern: 'greet',
public: true,
isGroup: true, // This command works only in groups
desc: 'Send a group greeting',
type: 'fun'
},
async (message) => {
await message.send('Hello, everyone!');
}
);
By AstroX11