Skip to content

A powerful Node.js Telegram bot offering advanced moderation, fun commands, music downloads, and MongoDB integration for data persistence.

License

Notifications You must be signed in to change notification settings

1dev-hridoy/Nexalo

Repository files navigation

Nexalo Bot Banner

Nexalo - Advanced Telegram Bot

Node.js Support Project Version Code Version MIT LICENSE

A feature-rich Telegram bot built with Node.js that provides various utility, moderation, and entertainment commands.

Nexalo Setup Tutorial Nexalo Setup Tutorial Nexalo Setup Tutorial

Table of Contents

Features

  • 🛡️ Advanced group moderation (kick, ban, mute, warn)
  • 🎵 Music and video downloads
  • 🎮 Fun commands and games
  • 🔧 Utility functions
  • 📊 MongoDB integration for data persistence
  • ⚡ Fast and efficient command handling

Prerequisites

  • Node.js v16.x or higher
  • MongoDB v4.x or higher
  • A Telegram Bot Token (get it from @BotFather)
  • Basic knowledge of JavaScript/Node.js

Installation

  1. Clone the repository:
git clone https://github.com/1dev-hridoy/Nexalo.git
cd nexalo
  1. Install dependencies:
npm install
  1. Rename a example.env To .env file in the root directory:
BOT_TOKEN=YOUR_BOT_TOKEN
OWNER_ID=OWNER_ID_HERE
ADMIN_IDS=comma_separated_admin_ids
MONGODB_URI=YOUR_MONGODB_URI
  1. Start the bot:
npm start

Configuration

The bot uses environment variables for configuration. Create a .env file with the following variables:

  • BOT_TOKEN: Your Telegram bot token
  • MONGODB_URI: MongoDB connection string
  • OWNER_ID: Your Telegram user ID (for owner-only commands)

Command Structure

Commands should be created in the commands directory with the following structure:

module.exports = {
  name: 'commandname',
  adminOnly: false,
  ownerOnly: false,
  category: 'Category',
  description: 'Command description',
  guide: 'How to use the command',
  execute: async (bot, msg, args) => {
    // Command logic here
  }
};

Command Properties

  • name: Command name (without the / prefix)
  • adminOnly: Whether the command requires admin privileges
  • ownerOnly: Whether the command is restricted to bot owner
  • category: Command category for help menu organization
  • description: Brief description of what the command does
  • guide: Usage instructions
  • execute: Async function containing command logic

Creating Commands

Here's a step-by-step guide to creating new commands:

  1. Create a new file in the commands directory:
// commands/hello.js
module.exports = {
  name: 'hello',
  adminOnly: false,
  ownerOnly: false,
  category: 'Fun',
  description: 'Sends a greeting',
  guide: 'Use /hello to receive a greeting',
  execute: async (bot, msg, args) => {
    await bot.sendMessage(msg.chat.id, 'Hello! 👋');
  }
};
  1. The command will be automatically loaded by the bot.

Advanced Command Example

Here's an example of a more complex command with argument handling and error checking:

// commands/remind.js
module.exports = {
  name: 'remind',
  adminOnly: false,
  ownerOnly: false,
  category: 'Utility',
  description: 'Set a reminder',
  guide: 'Use /remind <time> <message>',
  execute: async (bot, msg, args) => {
    if (args.length < 2) {
      return bot.sendMessage(msg.chat.id, 'Please provide time and message');
    }

    const time = parseInt(args[0]);
    const message = args.slice(1).join(' ');

    if (isNaN(time)) {
      return bot.sendMessage(msg.chat.id, 'Please provide a valid time in minutes');
    }

    setTimeout(() => {
      bot.sendMessage(msg.chat.id, `Reminder: ${message}`);
    }, time * 60000);

    await bot.sendMessage(msg.chat.id, `Reminder set for ${time} minutes from now`);
  }
};

Database Setup

The bot uses MongoDB for data persistence. Here's how to set up your database:

  1. Create a MongoDB database
  2. Set up collections:
    • warnings: Store user warnings
    • settings: Store group settings
    • userdata: Store user-specific data

Database Schema Examples

Warnings Collection:

{
  userId: String,
  username: String,
  chatId: String,
  reason: String,
  timestamp: Date
}

Settings Collection:

{
  chatId: String,
  welcomeMessage: String,
  antiSpam: Boolean,
  maxWarnings: Number
}

Mongo DB Add Balance To User Account

const { ObjectId } = require('mongodb');

module.exports = {
  name: 'addCoins',
  adminOnly: false, // Set to true if only admins should use this command
  ownerOnly: false, // Set to true if only the bot owner should use this command
  category: 'Economy',
  description: 'Add coins to a user\'s balance',
  guide: 'Use /addCoins to add coins to your account',
  execute: async (bot, msg, args, db) => {
    const userId = msg.from.id;
    const chatId = msg.chat.id;
    const coinAmount = 10; // Amount to add

    try {
      const user = await db.collection('users').findOne({ userId });

      if (user) {
        await db.collection('users').updateOne(
          { userId },
          { $inc: { balance: coinAmount } }
        );
      } else {
        await db.collection('users').insertOne({
          userId,
          balance: coinAmount,
          lastDaily: new Date(0) // Initialize lastDaily if not needed immediately
        });
      }

      bot.sendMessage(chatId, `10 coins have been added to your balance!`);
    } catch (error) {
      console.error('Error in addCoins command:', error);
      bot.sendMessage(chatId, 'An error occurred while processing your request.');
    }
  }
};

Use User Account Balance/Coin

const { ObjectId } = require('mongodb');

module.exports = {
  name: 'usecoin',
  adminOnly: false,
  ownerOnly: false,
  category: 'Economy',
  description: 'Use 10 coins for a special action!',
  guide: 'Use /usecoin to spend 10 coins on an action',
  execute: async (bot, msg, args, db) => {
    const userId = msg.from.id;
    const chatId = msg.chat.id;
    const coinCost = 10; // Cost of the action in coins

    try {
      // Check user balance
      const user = await db.collection('users').findOne({ userId });
      if (!user || user.balance < coinCost) {
        return bot.sendMessage(chatId, `Insufficient balance. You need at least ${coinCost} coins to perform this action.`);
      }

      // Perform the action (e.g., sending a confirmation message)
      await bot.sendMessage(chatId, 'You have successfully used 10 coins for this special action!');

      // Deduct 10 coins from user's balance
      await db.collection('users').updateOne(
        { userId },
        { $inc: { balance: -coinCost } }
      );

      bot.sendMessage(chatId, `${coinCost} coins have been deducted from your account.`);
    } catch (error) {
      console.error('Error in usecoin command:', error);
      bot.sendMessage(chatId, 'An error occurred while processing your request. Please try again later.');
    }
  }
};

Contributing

  1. Fork the repository
  2. Submit a pull request

Coding Standards

  • Use ES6+ features
  • Maintain consistent error handling
  • Add comments for complex logic
  • Follow the existing command structure
  • Test thoroughly before submitting

License

This project is licensed under the MIT License - see the LICENSE file for details.

Support

If you need help or have questions:

  • Open an issue on GitHub
  • Contact the bot owner through Telegram
  • Check the Wiki for additional documentation

Contact Options

Discord Telegram Instagram YouTube
Facebook QR
Eliana Support Server
Telegram QR
BD_NOOBRA
Twitter QR
HridoyCode
YouTube QR
Hridoy Code

Made with ❤️ by Hridoy