Skip to content

The Bot Instance

The Bot (or Whatsbotcord) instance is the absolute core of your application. It manages the underlying WhatsApp socket connection, orchestrates the middleware pipeline, handles incoming events, and serves as the registry for all your commands.


To get your bot up and running, you only need to instantiate it and call .Start().

[!NOTE] Even though this code starts the bot and connects it to WhatsApp, it won’t actually do anything when users message it yet! The bot relies entirely on commands and event listeners to interact.

To learn how to create your first command, check out the Quick Start guide or explore the Guides & Tutorials section.

import Whatsbotcord from "whatsbotcord";
const bot = new Whatsbotcord({
commandPrefix: "!",
loggerMode: "recommended",
});
bot.Start();

The Bot instance exposes several powerful modules that you will use to shape your application.

  • bot.Commands: The built-in command registry. Use bot.Commands.Add(myCommand) to register new commands. The arguments you receive there are fully detailed in our Command Arguments page.
  • bot.Use(...): The middleware pipeline manager. You can seamlessly intercept messages before they reach commands by learning about our Middleware pipeline.
  • bot.Events: The global event emitter. Subscribe to socket events or command lifecycle hooks in the Events system.
  • bot.SendMsg & bot.ReceiveMsg: Direct access to the internal sending and receiving managers for advanced cross-chat broadcasting available inside the Additional API global tools.

The Whatsbotcord constructor accepts an extensive set of configuration properties to fine-tune prefixes, connection throttling, error handling, interactive prompt defaults, and more.

The main options you should always set or at least be aware of.

PropertyTypeDefaultDescription
commandPrefixstring | string[]'!'Character(s) used to prefix commands. Configure multiple prefixes with an array (e.g. ['!', '/']).
tagPrefixstring | string[]'@'Character(s) used to tag the bot in messages (especially useful in group contexts).
credentialsFolderstring"./auth"Path to the folder where WhatsApp session credentials are stored.
loggerModeWhatsSocketLoggerMode"debug"Logging verbosity level (e.g. "recommended", "silent", "debug", "error").
ignoreSelfMessagebooleantrueIf true, the bot ignores messages sent by its own account to prevent infinite loops.

Tweak these options if you experience high concurrency messaging or encounter problems with WhatsApp rate-limiting your bot.

PropertyTypeDefaultDescription
maxReconnectionRetriesnumber5Maximum number of reconnection attempts if the socket drops unexpectedly.
senderQueueMaxLimitnumber20Maximum number of messages queued globally. Buffers pending output to avoid dropping messages.
delayMilisecondsBetweenMsgsnumber100Delay between sending queued messages to prevent spamming/flooding the WhatsApp API.

Configure how the bot reacts when a command crashes or throws an unhandled exception.

[!TIP] Keeping enableCommandSafeNet enabled is highly recommended for production to prevent your entire script from fatally crashing if a single command errors out.

PropertyTypeDefaultDescription
enableCommandSafeNetbooleantrueCaught internal errors won’t crash the entire bot.
defaultEmojiToSendReactionOnFailureCommandstring | nullundefinedEmoji to react with on the triggering message if a command fails unexpectedly (e.g. "⚠️" or "❌").
sendErrorToChatOnFailureCommand_debugbooleanfalseSends a JSON representation of the caught error to the chat. Excellent for real-time debugging!

These defaults define the behavior of ChatContext methods like WaitYesOrNoAnswer(). Setting them here saves you from configuring them manually on every command.

PropertyTypeDefaultDescription
cancelKeywordsstring[]VariesWords that correctly cancel a running command or interactive prompt.
positiveAnswerOptionsstring[]VariesKeywords interpreted as an affirmative (“yes”) response in WaitYesOrNoAnswer (case-insensitive).
negativeAnswerOptionsstring[]VariesKeywords interpreted as a negative (“no”) response in WaitYesOrNoAnswer (case-insensitive).
timeoutSecondsnumber30Default time limit for awaiting user input during interactive commands.

These options are primarily intended for maintainers or advanced users writing automated integration tests. Incorrect usage can break the bot’s standard behavior.

PropertyTypeDescription
ownWhatsSocketImplementation_InternalIWhatsSocketReplaces the built-in WhatsApp socket implementation.
ownChatContextCreationHook_Internal() => IChatContext | nullReplaces the default ChatContext that is sent to all commands.