mirror of
https://github.com/eternnoir/pyTelegramBotAPI.git
synced 2023-08-10 21:12:57 +03:00
add-new-example
This commit is contained in:
parent
0f52ca688f
commit
55fffd829f
17
examples/new_chat_members_example.py
Normal file
17
examples/new_chat_members_example.py
Normal file
@ -0,0 +1,17 @@
|
||||
from telebot.async_telebot import AsyncTeleBot
|
||||
from asyncio import run
|
||||
|
||||
bot = AsyncTeleBot('YOUR TOKEN')
|
||||
YOUR_CHAT_ID = 'your chat id' # capture the CHAT_ID of your private chat and put it here
|
||||
|
||||
@bot.message_handler(content_types=['new_chat_members']) # manages all new member events for all groups
|
||||
async def Welcome(message):
|
||||
try:
|
||||
new_member = message.json['new_chat_member']['first_name'] # 'new_member' takes the first name from the dictionary in
|
||||
name_group = message.json['chat']['title'] # 'name_group' take the name of the group and send it along with the welcome message
|
||||
await bot.send_message(
|
||||
message.chat.id, f'Welcome to Hubber, @{new_member}🤖 you have been added to the group: *{name_group}*', parse_mode='Markdown') # welcome message
|
||||
except Exception as err:
|
||||
await bot.send_message(YOUR_CHAT_ID, text=err) # if it falls into an exception, the bot sends the error to your private without breaking the code
|
||||
|
||||
run(bot.polling(non_stop=True))
|
Loading…
x
Reference in New Issue
Block a user