Skip to content

Tags & Groups

Commands can be invoked as Tags instead of normal prefixes. By default, tags are triggered via @. You can change this behavior setting the tagPrefix option when creating your Bot.

Here we’ll create a command that works exactly like Discord’s @everyone by fetching all group members, wrapping their IDs in mention syntax, and sending a broadcast.

import Bot, { CommandType, CreateCommand } from "whatsbotcord";
const everyoneTag = CreateCommand(
"everyone",
async (chat, api, args) => {
// Fetch properties from the current group context
const res = await chat.FetchGroupData();
if (res) {
/**
* `res.members` contains everyone's formatted IDs
* abstracted for you by the library!
*/
const mentions = res.members.map((m) => m.asMentionFormatted);
const ids = res.members.map((m) => m.rawId);
// Reply with all mentions, telling WhatsApp who to actually tag
await chat.SendText(mentions.join(" "), { mentionsIds: ids });
}
},
// Now it can be used like @e
{ aliases: "e" }
);
const bot = new Bot({
commandPrefix: ["!"],
tagPrefix: ["@"],
credentialsFolder: "./auth",
});
/** IMPORTANT: Use CommandType.Tag prop to make it use the @ prefix */
bot.Commands.Add(everyoneTag, CommandType.Tag);
bot.Start();

Now whenever someone sends "@everyone" or "@e", the bot will broadcast out the mention block. (Note: the bot must have permissions/presence in that group to read group data and send messages).