如何跟踪向频道添加和删除机器人程序的事件



我在aiogram上有一个Telegram机器人,当我的机器人被添加或从频道中删除时,我希望得到通知。但我的代码只适用于组。需要做些什么才能在频道上工作?

这是代码:

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)

请改用my_chat_member_handler

更多信息:https://core.telegram.org/bots/api-changelog#march-9-2021

添加了两种新的更新类型

添加了有关聊天中成员状态更改的更新,由类ChatMemberUpdated和字段my_chat_member和chat_member在Update类中。机器人必须是聊天中的管理员才能接收其他聊天室成员的聊天室成员更新。默认情况下,仅my_chat_member收到关于机器人程序本身的更新。

最新更新