如何跟踪添加和删除机器人到频道的事件?
我在 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)
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)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
请改用
my_chat_member_handler
。更多信息:https://core.telegram.org/bots/api -changelog#2021年3月9日
Use
my_chat_member_handler
instead.More info: https://core.telegram.org/bots/api-changelog#march-9-2021