Answer the question
In order to leave comments, you need to log in
Mistake in writing Telegram bot filters?
When writing a moderator bot in telegrams, there is an error in the filters. I tried many ways and options, but nothing helps.
(Aiogram 3)
bot.py:
import config
import logging
from filter import IsAdminFilter
from aiogram import Bot, Dispatcher, executor, types
logging.basicConfig(level=logging.INFO)
bot = Bot(token=config.TOKEN)
dp = Dispatcher(bot)
dp.filters_factory.bind(IsAdminFilter)
#ban command for admin
@dp.message(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.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)
filter.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: types.Message):
member = await message.bot.get_chat_member(message.chat.id, message.from_user.id)
return member.is_chat_admin()
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question