Guest User

Untitled

a guest
Apr 17th, 2026
27
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.89 KB | None | 0 0
  1. CHANNEL_USERNAME = ""
  2.  
  3. async def check_membership(user_id, bot):
  4. member = await bot.get_chat_member(CHANNEL_USERNAME, user_id)
  5. return member.status in ["member", "administrator", "creator"]
  6.  
  7. async def start(update: Update, context: ContextTypes.DEFAULT_TYPE):
  8. user_id = update.effective_user.id
  9.  
  10. if await check_membership(user_id, context.bot):
  11. await update.message.reply_text("✅ Welcome! You can now use the bot.")
  12. else:
  13. keyboard = [
  14. [InlineKeyboardButton("Join Channel", url=f"https://t.me/{CHANNEL_USERNAME[1:]}")],
  15. [InlineKeyboardButton("I've Joined", callback_data="check_join")]
  16. ]
  17.  
  18. reply_markup = InlineKeyboardMarkup(keyboard)
  19.  
  20. await update.message.reply_text(
  21. "🚫 You must join our channel before using this bot.",
  22. reply_markup=reply_markup
  23. )
Advertisement
Add Comment
Please, Sign In to add comment