2021-11-27 21:41:39 +03:00
|
|
|
from telebot import types,util
|
|
|
|
from telebot.async_telebot import AsyncTeleBot
|
2021-11-27 23:04:49 +03:00
|
|
|
|
2021-11-27 21:41:39 +03:00
|
|
|
bot = AsyncTeleBot('TOKEN')
|
|
|
|
|
|
|
|
#chat_member_handler. When status changes, telegram gives update. check status from old_chat_member and new_chat_member.
|
|
|
|
@bot.chat_member_handler()
|
|
|
|
async def chat_m(message: types.ChatMemberUpdated):
|
|
|
|
old = message.old_chat_member
|
|
|
|
new = message.new_chat_member
|
|
|
|
if new.status == "member":
|
|
|
|
await bot.send_message(message.chat.id,"Hello {name}!".format(name=new.user.first_name)) # Welcome message
|
|
|
|
|
|
|
|
#if bot is added to group, this handler will work
|
|
|
|
@bot.my_chat_member_handler()
|
|
|
|
async def my_chat_m(message: types.ChatMemberUpdated):
|
|
|
|
old = message.old_chat_member
|
|
|
|
new = message.new_chat_member
|
|
|
|
if new.status == "member":
|
|
|
|
await bot.send_message(message.chat.id,"Somebody added me to group") # Welcome message, if bot was added to group
|
|
|
|
await bot.leave_chat(message.chat.id)
|
|
|
|
|
|
|
|
#content_Type_service is:
|
|
|
|
#'new_chat_members', 'left_chat_member', 'new_chat_title', 'new_chat_photo', 'delete_chat_photo', 'group_chat_created',
|
|
|
|
#'supergroup_chat_created', 'channel_chat_created', 'migrate_to_chat_id', 'migrate_from_chat_id', 'pinned_message',
|
2022-04-23 15:03:54 +03:00
|
|
|
#'proximity_alert_triggered', 'video_chat_scheduled', 'video_chat_started', 'video_chat_ended',
|
|
|
|
#'video_chat_participants_invited', 'message_auto_delete_timer_changed'
|
2021-11-27 21:41:39 +03:00
|
|
|
# this handler deletes service messages
|
|
|
|
|
|
|
|
@bot.message_handler(content_types=util.content_type_service)
|
|
|
|
async def delall(message: types.Message):
|
|
|
|
await bot.delete_message(message.chat.id,message.message_id)
|
2021-12-12 13:07:30 +03:00
|
|
|
import asyncio
|
2022-03-08 10:07:00 +03:00
|
|
|
asyncio.run(bot.polling(allowed_updates=util.update_types))
|