При попытке запуска бота, выдает ошибку AttributeError: type object 'type' has no attribute 'Message'
$ python main2.py
Traceback (most recent call last):
File "main2.py", line 5, in <module>
from filters import IsAdminFilter
File "/home/boris/py/ParOk/filters.py", line 5, in <module>
class IsAdminFilter(BoundFilter):
File "/home/boris/py/ParOk/filters.py", line 11, in IsAdminFilter
async def check(self, message: type.Message):
AttributeError: type object 'type' has no attribute 'Message'
main2.py
import config
import logging
from aiogram import Bot, Dispatcher, executor, types
from filters import IsAdminFilter
# log level
logging.basicConfig(level=logging.INFO)
# Инициализация бота
bot = Bot(token=config.TOKEN)
dp = Dispatcher(bot)
# Активация фильтров
dp.filters_factory.bind(IsAdminFilter)
# Удаление уведомления о новом входе
@dp.message_handler(content_types=["new_chat_members"])
async def on_user_joined(message: types.Message):
await message.delete()
# /Ban
@dp.message_handler(is_admin=True, commands=["ban"], commands_prefix="!/")
async def cmd_ban(message: types.Message):
if not message.reply_to_message:
await message.reply("Эта команда должна быть ответом на сообщение!")
return
await message.bot.delete_message(chat_id=config.GROUP_ID, message_id=message.message_id)
await message.bot.kick_chat_member(chat_id=config.GROUP_ID, user_id=message.reply_to_message.from_user.id)
await message.reply_to_message.reply("Пользавтель заблокирован")
if __name__ == "__main__":
executor.start_polling(dp, skip_updates=False)
filters.py
from aiogram import types
from aiogram.dispatcher.filters import BoundFilter
class IsAdminFilter(BoundFilter):
key = "is_admin"
def __init__(self, is_admin):
self.is_admin = is_admin
async def check(self, message: type.Message):
member = await message.bot.get_chat_member(message.chat.id, message.from_user.id)
return member.is_chat_admin()