Skip to content

Instantly share code, notes, and snippets.

@nuhmanpk
Last active December 27, 2024 18:04
Show Gist options
  • Select an option

  • Save nuhmanpk/3020cc3a0d7ed658aa4d8900781e1a6d to your computer and use it in GitHub Desktop.

Select an option

Save nuhmanpk/3020cc3a0d7ed658aa4d8900781e1a6d to your computer and use it in GitHub Desktop.
Add Force Subscribe To Your Bot
import pyrogram
from pyrogram import Client, filters
from pyrogram.types import InlineKeyboardMarkup, InlineKeyboardButton
from pyrogram.types import User, Message
from pyrogram.errors import UserNotParticipant
UPDATE_CHANNEL= "channel name without '@'"
# Follow me on Github - Github.com/nuhmanpk
# Join @BugHunterBots for more
FORCE_BUTTON = InlineKeyboardMarkup(
[[
InlineKeyboardButton('JOIN HERE 🔖', url=f"https://t.me/{UPDATE_CHANNEL}")
]]
)
@app.on_message(filters.command(["start"]) & filters.private)
async def start(bot, update):
try:
user = await bot.get_chat_member(UPDATE_CHANNEL, update.from_user.id)
if user.status == "member":
text = ""
reply_markup = # BUTTON_NAME
await update.reply_text(
text=text,
disable_web_page_preview=True,
reply_markup=reply_markup,
quote=True
)
# Add Your Code here to execute , if the
# user is member of Your channel
except UserNotParticipant:
await update.reply_text(
text="You need to Join my Updates Channel to Use me and Try Again\n @BugHunterBots",
disable_web_page_preview=True,
reply_markup=FORCE_BUTTON,
quote=True
)
return
# © BugHunterBots © 2021
# [email protected] | Bughunter0 | Nuhman
@M-fazin
Copy link

M-fazin commented Sep 6, 2021

Hy piro

@nuhmanpk
Copy link
Author

nuhmanpk commented Sep 6, 2021

piro?

@Mrvishal2k2
Copy link

Mrvishal2k2 commented Sep 7, 2021

#Suggestion
Defining app makes more clear to newbies I guess 👍

app = Client(.......)

And handling other exception also could be helpful if something unexpected goes wrong...

except Exception as error:
return await update.reply(f"Error\n{error}",True)

For usernotparticipant need to be return 🥺 else it won't block users to join
Instead continues with further codes

Copy link

ghost commented Oct 4, 2021

How to use this?

@pencemo
Copy link

pencemo commented Oct 31, 2021

Can i use this cod in c/c++ language

@Mrvishal2k2
Copy link

Can i use this cod in c/c++ language

No

@rajeshsaini2115
Copy link

rajeshsaini2115 commented Nov 27, 2021

add refresh callback button below join Channel

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment