Skip to content

Quick Start

Initialize a functional bot instance and register a fundamental command in minutes.

  1. Create your project file

    Create a new file (e.g. index.ts or index.js) in your project.

  2. Add the bot code

    import Whatsbotcord from "whatsbotcord";
    import type { AdditionalAPI, CommandArgs, IChatContext, ICommand } from "whatsbotcord/types";
    const bot = new Whatsbotcord({
    commandPrefix: "!",
    tagPrefix: "@",
    });
    class PingCommand implements ICommand {
    name: string = "ping";
    aliases?: string[] | undefined = ["p"];
    public async run(ctx: IChatContext, api: AdditionalAPI, args: CommandArgs): Promise<void> {
    await ctx.SendText("pong!");
    }
    }
    bot.Commands.Add(new PingCommand());
    bot.Start();
  3. Run your bot

    Terminal window
    npx tsx index.ts
  4. Scan the QR code

    A QR code will appear in your terminal. Open WhatsApp on your phone → Linked Devices → Scan the code.

The Bot constructor accepts a rich set of configuration properties. You can easily configure basic prefixes, connection throttling, error handling, interactive prompt defaults, and more. These are the most important ones:

import Whatsbotcord, { BaileysAdapter } from "whatsbotcord";
import type { AdditionalAPI, CommandArgs, IChatContext, ICommand } from "whatsbotcord/types";
const bot = new Whatsbotcord({
// -------------------------------------------------------------------
// 1. Basic Options
// -------------------------------------------------------------------
// Which characters should trigger a command? (Array or string)
commandPrefix: ["!", "."],
// Which characters should trigger a tag-based command?
tagPrefix: ["@"],
// Should the bot capture its own messages? (By default: false)
ignoreSelfMessage: false,
// This are the logs from the library by itself.
loggerMode: "recommended"
}, new BaileysAdapter({ /** **OPTIONAL PARAM**, in case you need to configure the credentialsFolder when login with QR (Baileys.js specific behaviour)*/
// Where to store the WhatsApp session authentication files (By default in local ./auth directory)
credentialsFolder: "./auth",
// Console logging detail level ("silent", "error", "debug", "recommended")
// This are the logs, but exclusively from the BaileysAdapter. (Not related to loggerMode from 6 lines above)
loggerMode: "recommended",
}));
class PingCommand implements ICommand {
name: string = "ping";
aliases?: string[] | undefined = ["p"];
public async run(ctx: IChatContext, api: AdditionalAPI, args: CommandArgs): Promise<void> {
await ctx.SendText("pong!");
}
}
bot.Commands.Add(new PingCommand());
bot.Start();
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).
ignoreSelfMessagebooleantrueIf true, the socket ignores messages sent by the bot itself.

Check the Bot page