Skip to content

Commit c2da2a6

Browse files
committed
Update welcome_bot.py
1 parent be7194f commit c2da2a6

1 file changed

Lines changed: 7 additions & 14 deletions

File tree

examples/welcome_bot.py

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,27 @@
11
"""This is the Welcome Bot in @PyrogramChat.
22
33
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.
55
"""
66

77
from pyrogram import Client, Emoji, Filters
88

9+
MENTION = "[{}](tg://user?id={})"
10+
MESSAGE = "{} Welcome to [Pyrogram](https://docs.pyrogram.ml/)'s group chat {}!"
11+
912
app = Client("my_account")
1013

1114

1215
@app.on_message(Filters.chat("PyrogramChat") & Filters.new_chat_members)
1316
def welcome(client, message):
1417
# 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]
1919

2020
# 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))
2522

2623
# 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)
3225

3326

3427
app.run() # Automatically start() and idle()

0 commit comments

Comments
 (0)