This project is a Telegram bot that uses Selenium, Chromedriver, Nircmd and system commands to automate tasks such as browser control, system command execution, screenshot capture, file download, mouse and keyboard emulator. The following guide will help you set up, configure, and package the project.
- Latest Python version
- Brave or Google Chrome browser
- Download Chromedriver using the Stable channel and make sure it is compatible with your browser version.
- Nircmd 64 bit version
- Open Telegram and search for @BotFather.
- Type the command
/newbot
to create a new bot. - Follow the instructions, provide a name and username for your bot.
- Once created, you will receive a Token. Save this token and add it to the line
TOKEN = 'ENTER YOUR BOT TOKEN'
in the source file.
Run the following command to install the necessary third-party libraries:
pip install pyautogui pillow nest_asyncio selenium pyinstaller pynput python-telegram-bot
- Determine the version of Brave/Chrome you are using:
- Open your browser and navigate to
Settings > About Brave/Chrome
to check the version.
- Open your browser and navigate to
- Download the compatible Chromedriver from the official website.
- Extract Chromedriver and save the path to the
chromedriver.exe
file.
Enter this path in the line: CHROME_DRIVER_PATH = "CHROME_DRIVER_PATH = "ENTER YOUR PATH TO CHROMEDRIVER.EXE"
- Determine the installation path of your browser:
- Brave: Typically located at
C:/Program Files/BraveSoftware/Brave-Browser/Application/brave.exe
. - Chrome: Typically located at
C:/Program Files/Google/Chrome/Application/chrome.exe
.
- Brave: Typically located at
- Enter this path in the line: BRAVE_PATH = "ENTER YOUR PATH TO BRAVE.EXE"
- User data contains information like cookies and browser settings, which helps the bot open your correct account.
- The default paths are usually:
- Brave:
C:/Users/<Your Username>/AppData/Local/BraveSoftware/Brave-Browser/User Data
. - Chrome:
C:/Users/<Your Username>/AppData/Local/Google/Chrome/User Data
.
- Brave:
- Enter this path in the line: USER_DATA_DIR = "ENTER YOUR PATH TO BRAVE USER DATA"
- Download NirCmd from the official website.
- Extract the contents and note the path to nircmdc.exe.
- Enter this path in the following lines of the function handle_volume_control: os.system("ENTER YOUR PATH TO NIRCMDC.EXE changesysvolume -3277") # Decrease volume os.system("ENTER YOUR PATH TO NIRCMDC.EXE changesysvolume 3277") # Increase volume
Copy the token you obtained from @BotFather and enter it in the line: TOKEN = 'ENTER YOUR BOT TOKEN'
- Open a terminal in the directory containing the source file.
- First, check in the IDE. If everything is set up correctly, the bot will start listening for commands on Telegram. Then, it's time to package the bot.
- You can also run the command to start the bot in the terminal (note that the terminal running the command must be in the same folder as the TelegramBotControlComputer.py file):
python TelegramBotControlComputer.py
- Package the source file into a standalone
.exe
file:pyinstaller --onefile TelegramBotControlComputer.py
- The executable file will be saved in the
dist/TelegramBotControlComputer.exe
directory.
- Ensure Chromedriver matches your browser version. Check again if Selenium fails to launch.
- Make sure the paths (
CHROME_DRIVER_PATH
,BRAVE_PATH
,USER_DATA_DIR
,LINE 203
,LINE 206
,TOKEN
) are entered correctly. - Do not share your Telegram Token publicly to avoid unauthorized control of your bot.
- If you get error message "Telegram.error.Timeout: Timed out". You just need to Revoke old token and Renew new token, then everything will be fine.
Lê Phi Anh
- Discord: LePhiAnhDev
- Telegram: @lephianh386ht
- GitHub: LePhiAnhDev