1

I have a Telegram Bot on aiogram, and I want to be notified when my bot is added or removed from channels. But my code only works on groups. What needs to be done to work on channels as well?

And here is the code:

import logging
from aiogram import Bot, Dispatcher, executor, types

from config import API_TOKEN

logging.basicConfig(level=logging.INFO)

bot = Bot(token=API_TOKEN)
dp = Dispatcher(bot)

@dp.message_handler(content_types=[types.ContentType.NEW_CHAT_MEMBERS, types.ContentType.LEFT_CHAT_MEMBER])
async def check_channel(message: types.Message):
    print(message)

if __name__ == "__main__":
    executor.start_polling(dp, skip_updates=True)
Tomerikoo
  • 18,379
  • 16
  • 47
  • 61
Phoenix
  • 11
  • 1

1 Answers1

0

Use my_chat_member_handler instead.

More info: https://core.telegram.org/bots/api-changelog#march-9-2021

Added two new update types

Added updates about member status changes in chats, represented by the class ChatMemberUpdated and the fields my_chat_member and chat_member in the Update class. The bot must be an administrator in the chat to receive chat_member updates about other chat members. By default, only my_chat_member updates about the bot itself are received.

Oleg
  • 523
  • 2
  • 10