forked from ShivangKakkar/StringSessionBot
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmust_join.py
More file actions
32 lines (30 loc) · 1.29 KB
/
must_join.py
File metadata and controls
32 lines (30 loc) · 1.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
from env import MUST_JOIN
from pyrogram import Client, filters
from pyrogram.types import InlineKeyboardMarkup, InlineKeyboardButton, Message
from pyrogram.errors import ChatAdminRequired, UserNotParticipant, ChatWriteForbidden
@Client.on_message(filters.incoming & filters.private, group=-1)
async def must_join_channel(bot: Client, msg: Message):
if not MUST_JOIN: # Not compulsory
return
try:
try:
await bot.get_chat_member(MUST_JOIN, msg.from_user.id)
except UserNotParticipant:
if MUST_JOIN.isalpha():
link = "https://t.me/" + MUST_JOIN
else:
chat_info = await bot.get_chat(MUST_JOIN)
link = chat_info.invite_link
try:
await msg.reply(
f"You must join [this channel]({link}) to use me. After joining try again !",
disable_web_page_preview=True,
reply_markup=InlineKeyboardMarkup([
[InlineKeyboardButton("✨ Join Channel ✨", url=link)]
])
)
await msg.stop_propagation()
except ChatWriteForbidden:
pass
except ChatAdminRequired:
print(f"I'm not admin in the MUST_JOIN chat : {MUST_JOIN} !")