Написал бота для скачивание видео с ютуба на aiogram, но он выдает ошибку
Использую последнюю версию aiogram
код:
import asyncio
import os
import config
from aiogram import Bot, Dispatcher, types, filters
from pytube import YouTube
async def main():
bot = Bot(token=config.BOT_TOKEN)
dp = Dispatcher()
dp.bot = bot
@dp.message(filters.Command("download"))
async def handle_download(message: types.Message):
try:
video_url = message.text.split()[1]
save_path = "./"
await message.answer('Видео в обработке')
yt = YouTube(video_url)
stream = yt.streams.filter(resolution='720p', progressive=True).first()
video_file = stream.download(output_path=save_path)
await message.answer(f"Видео '{yt.title}' успешно загружено!")
with open(video_file, 'rb') as video:
await bot.send_video(message.chat.id, video)
os.remove(video_file)
await message.answer("Видео успешно отправлено и удалено с сервера.")
except Exception as e:
await message.answer(f"Произошла ошибка: {str(e)}")
await dp.start_polling()
if __name__ == '__main__':
asyncio.run(main())
Ошибка:
Traceback (most recent call last):
File "C:\Users\super\PycharmProjects\videobot\main.py", line 36, in <module>
asyncio.run(main())
File "C:\Users\super\AppData\Local\Programs\Python\Python312\Lib\asyncio\runners.py", line 194, in run
return runner.run(main)
^^^^^^^^^^^^^^^^
File "C:\Users\super\AppData\Local\Programs\Python\Python312\Lib\asyncio\runners.py", line 118, in run
return self._loop.run_until_complete(task)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\super\AppData\Local\Programs\Python\Python312\Lib\asyncio\base_events.py", line 664, in run_until_complete
return future.result()
^^^^^^^^^^^^^^^
File "C:\Users\super\PycharmProjects\videobot\main.py", line 33, in main
await dp.start_polling()
File "C:\Users\super\PycharmProjects\videobot\.venv\Lib\site-packages\aiogram\dispatcher\dispatcher.py", line 486, in start_polling
raise ValueError("At least one bot instance is required to start polling")
ValueError: At least one bot instance is required to start polling