D
D
DmlD2021-11-05 18:18:35
Python
DmlD, 2021-11-05 18:18:35

How to fix this issue on Aiogram?

import config
import logging
import filters

from aiogram import Bot, Dispatcher, executor, types

from filters import IsAdminFilter

# log level
logging.basicConfig(level=logging.INFO)

# bot init
bot = Bot(token=config.TOKEN)
dp = Dispatcher(bot)

# activate filters
@dp.filters_factory.bind(IsAdminFilter)

# 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("NONE")
    return

  await message.bot.delete_message(config_GROUP_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("User banned!")

# remove new user joined messages
@dp.message_handler(content_types=["new_chat_members"])
async def on_user_joined(message: types.Message):
  await message.delete()
# echo
@dp.message_handler()
async def echo(message: types.Message):
  if "bad word" in message.text:
    # profanity detected, remove
    await message.delete()

#run long-polling
if __name__ == "__main__":
  executor.start_polling(dp, skip_updates=True)


And the error:

Traceback (most recent call last):
  File "C:\Emilem\selvertone\bot.py", line 21, in <module>
    async def cmd_ban(message:types.Message):
TypeError: 'NoneType' object is not callable

Answer the question

In order to leave comments, you need to log in

1 answer(s)
L
LXSTVAYNE, 2021-11-07
@DmlD

Here is the official solution where the chat admin is used: https://github.com/aiogram/aiogram/blob/82d10844d7... . Not sure if you are using filter binding correctly.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question