Skip to content

Events

Whatsbotcord provides a curated list of events you can subscribe to. This allows you to hook into WhatsApp’s background activity, command lifecycles, and group updates.

You can access events through the bot.Events object:

const bot = new Bot({ /* config */ });
bot.Events.onGroupEnter.Subscribe((groupMetadata) => {
console.log(`Bot joined a new group: ${groupMetadata.subject}`);
});
bot.Events.onCommandNotFound.Subscribe((ctx, commandNameStrNotFound) => {
ctx.SendText(`Couldn't find command '!${commandNameStrNotFound}'. Try again.`);
});

Here are all the events you can listen to:

EventDescription
onGroupEnterTriggered when the bot is added to or joins a new group.
onGroupUpdateTriggered when a group updates its name, description, or members count.
onIncomingMsgTriggered when any message arrives. This is the most raw way to hook into incoming data.
onRestartTriggered when the bot restarts itself in the event of an error or connection drop.
onSentMessageTriggered immediately following a successful outgoing message.
onStartupAllGroupsInTriggered during boot when the bot syncs all the groups it is currently a part of.
onUpdateMsgTriggered on message edits, like someone reacting to an existing message with an emoji.
onCommandNotFoundTriggered when a user tries to execute a command that is not registered.
onMiddlewareEndTriggered after all middleware layers execute successfully (if defined).
onCommandFoundTriggered when a valid command is parsed and matched, right before it gets executed.
onCommandFoundAfterItsExecutionTriggered after a valid command finishes running (whether it succeeded or threw an error).