У меня очень часто такая ошибка AttributeError: 'Dispatcher' object has no attribute 'message_handler'
вот тут ошибка AttributeError: 'Dispatcher' object has no attribute 'message_handler'.
from aiogram import Bot, Dispatcher, types, F
from aiogram.types import Message
from aiogram.exceptions import TelegramBadRequest
import asyncio
from aiogram.filters import Command, CommandStart
import random
import time
import psutil
import pytube
import os
import re
import logging
startTime = time.time()
bot = Bot("6475302931:AAF8e5rDO6JYQCINJu7zXFbQukXbcgwd2mk")
dp = Dispatcher()
def getUptime():
"""
Returns the number of seconds since the program started.
"""
return time.time() - startTime
@dp.message(F.text.lower().in_(["фота"]))
async def send_photo(message: Message):
photo = "https://i.ibb.co/NKSkGv1/1.jpg"
await bot.send_photo(message.chat.id, photo, caption="fhfhfhfhfhffh")
@dp.message(F.text.lower().in_(["тест"]))
async def randim(message: Message):
greetings(Message)
logging.basicConfig(level=logging.INFO)
@dp.message_handler(commands=['download'])
async def download_video(message: types.Message):
try:
command, link = message.get_full_command().split(maxsplit=1)
if not link:
await message.reply("Please provide a TikTok video link.")
return
file_name = "video.mp4" # default file name
if len(link.split()) > 1:
link, file_name = link.split(maxsplit=1)
save_path = f"downloads/{file_name}"
if await download_tiktok_video(link, save_path):
await message.reply("Video downloaded successfully.")
with open(save_path, 'rb') as video:
await message.reply_video(video)
os.remove(save_path) # Delete the file after sending
else:
await message.reply("Failed to download the video.")
except ValueError:
await message.reply("Invalid command format. Please use /download {link} {filename}")
@dp.message(F.text.lower().in_(["ага"]))
async def greetings(message: Message):
nick1_result = message.from_user.username
nick2_result = message.reply_to_message.from_user.username
radom = random.randint(1, 2)
if radom == 1:
photo = "https://i.ibb.co/NKSkGv1/1.jpg"
await bot.send_photo(message.chat.id, photo, caption=f"@{nick1_result} ага ага @{nick2_result}")
elif radom == 2:
photo = "https://i.ibb.co/VBNw2X0/2.jpg"
await bot.send_photo(message.chat.id, photo, caption=f"@{nick1_result} ага ага @{nick2_result}")
@dp.message(F.text.lower().in_(["дебаг"]))
async def debug(message: Message):
uptime = getUptime()
ram = psutil.virtual_memory()[3]/1000000000
await message.reply(f"Аптайм: {uptime}\nram: {ram}")
# Скачивалки для ют и тт
async def handle_text(message: types.Message):
text = message.text
if text.startswith('https://www.youtube.com/'):
yt = text
await message.reply(f"Скачивание видео с Ютуба начинается")
url = f"{yt}"
yt = pytube.YouTube(url)
video = yt.streams.get_highest_resolution()
video.download()
original_filename = video.filename
new_filename = "1"
os.rename(original_filename, new_filename)
async def main():
await bot.delete_webhook(drop_pending_updates=True)
await dp.start_polling(bot)
if __name__ == "__main__":
asyncio.run(main())
В почти каждом @dp.message_handler() ошибка.
пробовал много чего, просто искал может одну букву ошибся, весь интернет перерыл, ничего