Skip to content

Cyberkingcr7/bnh-md

Repository files navigation

BNH Bot

A WhatsApp bot built with Node.js, TypeScript, and Firebase.

Prerequisites

Installation

  1. Clone the repository:

    git clone https://github.com/Cyberkingcr7/bnh-md
    cd bnh-md
  2. Install dependencies:

    yarn install
    # or
    npm install
  3. Firebase Setup:

    This bot uses Firebase for its database. You need to provide a service account key.

    1. Go to the Firebase Console.
    2. Select your project (or create a new one).
    3. Go to Project settings > Service accounts.
    4. Click Generate new private key.
    5. A JSON file will be downloaded.
    6. Rename this file to sui.json.
    7. Place sui.json in the root directory of the project (the same folder as package.json).

    Important: Do not share your sui.json file. It contains sensitive credentials.

Running the Bot

To start the bot, run:

tsc
npm start

If you want to host this bot , i'd suggest Railway or Fly.io.

Creating a Command

You can add new commands by creating files in the src/cmd directory. You can organize them into subfolders (e.g., src/cmd/General, src/cmd/MyCategory).

Basic Command Example

Create a new file, for example src/cmd/General/hello.ts:

import { Ctx } from "../../lib/ctx";

module.exports = {
  name: "hello",          // The command name (e.g., !hello)
  category: "General",    // Category for the help menu
  code: async (ctx: Ctx) => {
    // ctx contains information about the message and sender
    
    // Reply to the user
    await ctx.reply("Hello there! 👋");
  },
};

Command Structure

  • name: The trigger for the command (without the prefix).
  • category: The category under which the command will appear in the help menu.
  • code: An async function that executes the command logic. It receives a ctx (Context) object.

The ctx Object

The ctx object provides helper methods and properties to interact with the message and the user.

  • ctx.reply(text): Reply to the message with text.
  • ctx.sender.jid: The JID (ID) of the sender.
  • ctx.args: Array of arguments passed to the command.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages