|
1 | 1 | """This is the Welcome Bot in @PyrogramChat. |
2 | 2 |
|
3 | 3 | It uses the Emoji module to easily add emojis in your text messages and Filters |
4 | | -to make it only work for specific messages in a specific chat |
| 4 | +to make it only work for specific messages in a specific chat. |
5 | 5 | """ |
6 | 6 |
|
7 | 7 | from pyrogram import Client, Emoji, Filters |
8 | 8 |
|
| 9 | +MENTION = "[{}](tg://user?id={})" |
| 10 | +MESSAGE = "{} Welcome to [Pyrogram](https://docs.pyrogram.ml/)'s group chat {}!" |
| 11 | + |
9 | 12 | app = Client("my_account") |
10 | 13 |
|
11 | 14 |
|
12 | 15 | @app.on_message(Filters.chat("PyrogramChat") & Filters.new_chat_members) |
13 | 16 | def welcome(client, message): |
14 | 17 | # Build the new members list (with mentions) by using their first_name |
15 | | - new_members = ", ".join([ |
16 | | - "[{}](tg://user?id={})".format(i.first_name, i.id) |
17 | | - for i in message.new_chat_members |
18 | | - ]) |
| 18 | + new_members = [MENTION.format(i.first_name, i.id) for i in message.new_chat_members] |
19 | 19 |
|
20 | 20 | # Build the welcome message by using an emoji and the list we built above |
21 | | - text = "{} Welcome to [Pyrogram](https://docs.pyrogram.ml/)'s group chat {}!".format( |
22 | | - Emoji.SPARKLES, |
23 | | - new_members |
24 | | - ) |
| 21 | + text = MESSAGE.format(Emoji.SPARKLES, ", ".join(new_members)) |
25 | 22 |
|
26 | 23 | # Send the welcome message |
27 | | - client.send_message( |
28 | | - message.chat.id, text, |
29 | | - reply_to_message_id=message.message_id, |
30 | | - disable_web_page_preview=True |
31 | | - ) |
| 24 | + message.reply(text, disable_web_page_preview=True) |
32 | 25 |
|
33 | 26 |
|
34 | 27 | app.run() # Automatically start() and idle() |
0 commit comments