Skip to content
/ hydrogram-bot Public template

Template for Hydrogram bot - A pyrogram alternative

License

Notifications You must be signed in to change notification settings

nuhmanpk/hydrogram-bot

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

20 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Hydrogram-bot

This is a template for a Hydrogram bot using the Hyrogram framework a Pyrogram Alternative. Follow the steps below to set up and run the bot. For better developer experience install this code snippet extenstion.

Prerequisites

  • Python 3.8 or higher
  • MongoDB
  • Telegram account

Getting Started

  1. Clone the Repository Clone this repository to your local machine using:

    git clone https://github.com/nuhmanpk/hydrogram-bot.git
    cd hydrogram-bot
  2. Create a Virtual Environment Create a virtual environment to manage dependencies:

    python3 -m venv venv

    Activate the virtual environment:

    On Windows:

    venv\Scripts\activate
    

    On macOS/Linux:

    source venv/bin/activate
  3. Install Dependencies Install the required Python packages:

    pip install -r requirements.txt
  4. Obtain Required Values You need to gather the following values to configure your bot:

  5. Set Environment Variables Create a .env file in the root of your project directory and add the following content:

    DATABASE_URL=your_mongodb_url
    DATABASE_NAME=your_database_name
    BOT_TOKEN=your_bot_token
    API_ID=your_api_id
    API_HASH=your_api_hash
    

    Replace the placeholders (your_mongodb_url, your_database_name, your_bot_token, your_api_id, your_api_hash) with your actual values.

  6. Run the Bot Finally, run the bot with:

    python3 main.py
    

Connect to Your VM

  1. Install PM2 Install PM2, a process manager for Node.js applications that can also be used to manage Python processes:

    sudo npm install pm2 -g
  2. Start the Bot with PM2

    1. Start your bot using PM2:
    pm2 start python3 --name hydrogram-bot -- main.py
    1. To make PM2 start on system boot:
    pm2 startup
    pm2 save
  3. Monitor and Manage Your Bot You can manage your bot with PM2 using the following commands:

    1. List running processes:
    pm2 list
    1. Stop the bot:
    pm2 stop hydrogram-bot
    1. Restart the bot:
    pm2 restart hydrogram-bot
    1. View logs:
    pm2 logs hydrogram-bot

Happy Coding ... 🚀