i’m creating a telegram uploader bot but everytime it hits an error , I have not much knowledge of coding so help me

TypeError: Dispatcher._init_() takes 1 positional argument but 2 were given

and if i am doing this “dp = Dispatcher()” it will throw an error —

AttributeError: ‘Dispatcher’ object has no attribute ‘message_handler’

so help me

here is my code –


import os
import logging
import re
import toml
import asyncio
from aiogram import Bot, Dispatcher, types
from telegram.constants import ParseMode

CONFIG_FILE = "config.toml"

# Function to create a config file with the bot token
def create_config_file():
    bot_token = input("Enter your Telegram bot token: ")
    config_data = {"telegram": {"bot_token": bot_token}}
    with open(CONFIG_FILE, "w") as f:
        toml.dump(config_data, f)

# Load bot token from the TOML file or create the file if it doesn't exist
if not os.path.exists(CONFIG_FILE):
    create_config_file()

with open(CONFIG_FILE, "r") as f:
    config = toml.load(f)

bot_token = config["telegram"]["bot_token"]

# Initialize the Telegram bot with aiogram
bot = Bot(token=bot_token)
dp = Dispatcher(bot)

def extract_episode_number(file_name):
    match = re.search(r"E(d+)", file_name)
    if match:
        return int(match.group(1))
    return 0

# Enable logging (optional but recommended)
logging.basicConfig(format='%(asctime)s - %(name)s - %(levelname)s - %(message)s', level=logging.INFO)

# Define a function to handle the "/start" command
@dp.message_handler(commands=['start'])
async def start(message: types.Message):
    await message.reply_text(
        "Hi! I'm a bot that can upload video files. Just send me a video file and I'll do the rest."
    )

# Define a function to handle the video file upload
@dp.message_handler(content_types=types.ContentType.VIDEO)
async def handle_video_upload(message: types.Message):
    # Download the video file to the local storage
    file_id = message.video.file_id
    file_path = f"{file_id}.mp4"
    await bot.download_file_by_id(file_id, file_path)
    # Send the video file back to the chat
    with open(file_path, "rb") as video:
        await message.reply_document(video)
    # Send a confirmation message
    await message.reply_text("Video uploaded successfully!")

# Define a function to handle errors
@dp.errors_handler()
async def error_handler(update: types.Update, exception: Exception):
    logging.error(f"Update {update} caused error {exception}")

# Define a function to handle the directory upload
@dp.message_handler(commands=['dir'])
async def handle_directory_upload(message: types.Message):
    undone = []
    # Get the directory name from the message
    directory_name = " ".join(message.get_args())
    # Check if the directory exists
    if not os.path.exists(directory_name):
        await message.reply_text("Directory not found!")
        return
    await message.reply_text("Please wait while uploading the files...")
    # Get the list of video files in the directory
    video_files = []
    for root, _, files in os.walk(directory_name):
        for file in files:
            if file.endswith(".mp4"):
                video_files.append(os.path.join(root, file))

    sorted_episode_list = sorted(video_files, key=lambda file: extract_episode_number(file))

    # Upload each video file in the directory
    for video_file in sorted_episode_list:
        logging.info(f"Uploading: {video_file}")
        with open(video_file, "rb") as f:
            try:
                caption = os.path.relpath(video_file, directory_name)
                await message.reply_document(f, caption=caption)
            except Exception as e:
                logging.error(f"Error uploading {video_file}: {e}")
                undone.append(video_file)

    if undone:
        undone_files = "n".join([os.path.relpath(file, directory_name) for file in undone])
        await message.reply_text(f"These files could not be uploaded:n{undone_files}")
    else:
        await message.reply_text("All files uploaded successfully!")

# Main function to start the bot and handle the polling loop
async def main():
    logging.info("Bot Started!")
    await dp.start_polling()
    try:
        while True:
            await asyncio.sleep(1)
    except KeyboardInterrupt:
        logging.info("Bot stopped by user")
    finally:
        await dp.stop_polling()

if __name__ == '__main__':
    asyncio.run(main())

i want to try create an uploader but it didnt work

so can anyone told me what should i do

New contributor

learner is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật