module.exports = {
name: "Name of command",
info: "description of command",
dev: "Author",
onPrefix: true, // or false
dmUser: false, // true or false
nickName: ["alias1", "alias2"], // array of aliases
usages: "Usage instructions",
cooldowns: 10, // cooldown time in seconds
onLaunch: async function ({ api, event, actions }) {
// Command logic here
}
};
The onLaunch
function is executed when the command is called. It can handle initialization tasks and respond to the event.
Example:
onLaunch: async function ({ api, event, actions }) {
const message = "Command executed!";
await actions.reply(message);
}
The onEvents with Target
function is triggered with arguments, including the target.
Example:
onEvents: async function ({ api, event, target }) {
const targetText = target.join(" ");
if (!targetText) return actions.reply("Provide the Text");
// Function logic here
}
The onReply
function is executed when a user replies to a specific message. This allows for context-sensitive responses.
Example:
onReply: async function ({ reply, api, event }) {
const response = `You said: ${reply}`;
await actions.reply(response);
}
The callReact
function is invoked when a user reacts to a message. It enables confirmation actions or handling reactions.
Example:
callReact: async function ({ reaction, event, api }) {
if (reaction === '👍') {
await actions.reply("Confirmed!");
} else if (reaction === '👎') {
await actions.reply("Cancelled.");
}
}
The noPrefix
function allows the command to be executed without a prefix, useful for more natural interactions.
Example:
noPrefix: async function ({ api, event }) {
await actions.reply("This command can be executed without a prefix.");
}
The actions
object provides methods for responding to user interactions.
Respond to a user directly.
actions.reply("Hello!");
Send a message to the thread.
actions.send("Hello, everyone!");
React to the current message with an emoji.
actions.react("🔥");
Edit a previously sent message.
const loading = await actions.reply("Loading...");
actions.edit("Hello", loading.messageID);
Remove a user from the group.
actions.kick(userID);
Remove the bot from the current group.
actions.leave();
Share a contact with a specific user.
actions.share(contact, senderID);
You can use aliases for commands by defining a nickName
property in your command object. This allows multiple names for the same command.
Example:
module.exports = {
name: "test",
nickName: ["test", "testing"],
onLaunch: async function ({ api, event, actions }) {
await actions.reply("This is a test command.");
},
// other properties...
};
The dmUser
property indicates whether a command can be executed through direct messages. If dmUser
is true
, the command can be used in DMs.
Example:
module.exports = {
name: "example",
dmUser: true,
onLaunch: async function ({ api, event, actions }) {
await actions.reply("This command can be executed in DMs.");
},
// other properties...
};
This documentation provides an overview of how to implement and utilize commands in your bot. It highlights the event handling methods and action functionalities for responding to user interactions. Ensure to follow the structure and examples to integrate new commands effectively.