Use tg bot to automatically download and upload files from the channel to local & cloud storage.

1. Telegram API Application#

Open, select Apps after logging in, fill in the relevant information, and automatically generate apiId and apiHash information. If you have applied before, you can see it after entering Apps.

2. Building a Telegram Bot#

  1. Download the script
    git clone <>
  2. Install rclone. If you only need to download to your local machine, you don't need to install this step.
  3. Enter the script directory
    cd telegram_channel_downloader
  4. Install dependencies
    pip3 install -r requirements.txt
  5. Modify the relevant information in the file:

api_id, api_hash: Information obtained from the telegram api, fill in the corresponding positions respectively;

bot_token: Contact @BotFather to create a bot, it can also be an existing one. Fill in the obtained token;

admin_id: Contact @get_id_bot to send a random message and obtain it;

If you need to upload to OD: You should modify the following parameters in the script: drive_id="", drive_name='onedrive', onedrive is the name of the cloud drive you filled in when configuring rclone, and replace "fclone" with "rclone" on line 102;

There are corresponding notes for all configurations, modify them as needed.

  1. Run the script: Can be kept online with SCREEN
 # Enter the phone number associated with telegram, get the verification code and enter it

Screen related commands:

# Create a screen session:
screen -S xx      #xx is the name of the session to be created
# Hide and keep the current session window:
Press Ctrl+A, then press the "D" key
# Restore the session window:
screen -r xx      #Restore the session with the name xx
# If you forget or haven't set the session name:
screen -ls      #List all sessions, find and use the restore command
# Close the session window
  1. Run: Send /start followed by the link to the channel to the bot, and you can start running the script and downloading files.

Link to the channel: Click on your channel name to see the channel link;

0: This is the message ID, you can define it yourself. 0 represents the earliest message. If you want to download from a specific message onwards, right-click on the message and choose "Copy Message Link" to see the message ID number at the end of the link.

Ownership of this post data is guaranteed by blockchain and smart contracts to the creator alone.