A feature-rich Telegram bot built with Node.js that provides various utility, moderation, and entertainment commands.
- Features
- Prerequisites
- Installation
- Configuration
- Command Structure
- Creating Commands
- Available Commands
- Database Setup
- Contributing
- License
- 🛡️ 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
- 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
- Clone the repository:
git clone https://github.com/1dev-hridoy/Nexalo.git
cd nexalo
- Install dependencies:
npm install
- 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
- Start the bot:
npm start
The bot uses environment variables for configuration. Create a .env
file with the following variables:
BOT_TOKEN
: Your Telegram bot tokenMONGODB_URI
: MongoDB connection stringOWNER_ID
: Your Telegram user ID (for owner-only commands)
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
}
};
name
: Command name (without the / prefix)adminOnly
: Whether the command requires admin privilegesownerOnly
: Whether the command is restricted to bot ownercategory
: Command category for help menu organizationdescription
: Brief description of what the command doesguide
: Usage instructionsexecute
: Async function containing command logic
Here's a step-by-step guide to creating new commands:
- 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! 👋');
}
};
- The command will be automatically loaded by the bot.
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`);
}
};
The bot uses MongoDB for data persistence. Here's how to set up your database:
- Create a MongoDB database
- Set up collections:
warnings
: Store user warningssettings
: Store group settingsuserdata
: Store user-specific data
Warnings Collection:
{
userId: String,
username: String,
chatId: String,
reason: String,
timestamp: Date
}
Settings Collection:
{
chatId: String,
welcomeMessage: String,
antiSpam: Boolean,
maxWarnings: Number
}
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.');
}
}
};
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.');
}
}
};
- Fork the repository
- Submit a pull request
- Use ES6+ features
- Maintain consistent error handling
- Add comments for complex logic
- Follow the existing command structure
- Test thoroughly before submitting
This project is licensed under the MIT License - see the LICENSE file for details.
If you need help or have questions:
- Open an issue on GitHub
- Contact the bot owner through Telegram
- Check the Wiki for additional documentation
Discord | Telegram | YouTube | |
---|---|---|---|
Eliana Support Server |
BD_NOOBRA |
HridoyCode |
Hridoy Code |
Made with ❤️ by Hridoy