from telebot.async_telebot import AsyncTeleBot bot = AsyncTeleBot('TOKEN') @bot.message_handler(commands=['start', 'help']) async def send_welcome(message): await bot.reply_to(message, "Howdy, how are you doing?") @bot.message_handler(func=lambda message: True) async def echo_all(message): await bot.reply_to(message, message.text) import asyncio asyncio.run(bot.polling(skip_pending=True)) # to skip updates
from telebot.async_telebot import AsyncTeleBot import telebot bot = AsyncTeleBot('TOKEN') @bot.chat_join_request_handler() async def make_some(message: telebot.types.ChatJoinRequest): await bot.send_message(message.chat.id, 'I accepted a new user!') await bot.approve_chat_join_request(message.chat.id, message.from_user.id) import asyncio asyncio.run(bot.polling())
"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', #'proximity_alert_triggered', 'video_chat_scheduled', 'video_chat_started', 'video_chat_ended', #'video_chat_participants_invited', 'message_auto_delete_timer_changed' # 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) import asyncio asyncio.run(bot.polling(allowed_updates=util.update_types))