gpt-4-0314· openai
Suzhen/CodeChat
can you write a telegram bot using pyrogram python library which does this - ban the…
- User
can you write a telegram bot using pyrogram python library
which does this
- ban the person who joined the channel
- send a private invite link to him join the channel
and is this possible
- Assistant
Yes, it's possible to create a Telegram bot that would ban a user who joins a channel and send a private invite link to them. You can use Pyrogram to create the bot, which is a Python library for building Telegram clients.
Here is a simple example of how you can achieve this using Pyrogram:
import os from pyrogram import Client, filters # Set your API details api_id = os.environ["API_ID"] api_hash = os.environ["API_HASH"] bot_token = os.environ["BOT_TOKEN"] app = Client("BanBot", api_id=api_id, api_hash=api_hash, bot_token=bot_token) # Get the channel's private invite link channel_id = -100123456789 # replace with your channel id invite_link = "https://t.me/joinchat/abc" # replace with your channel's private invite link # Handler for new users joining a channel @app.on_message(filters.new_chat_members & filters.chat(channel_id)) async def ban_user(client, message): user = message.new_chat_members[0] await client.kick_chat_member(channel_id, user.id) text = f"Hello {message.from_user.mention()}, it looks like you've been banned from the channel. Join again using this private invite link: {invite_link}" await app.send_message(user.id, text) app.run()