Skip to content

Instantly share code, notes, and snippets.

@HeySreelal
Created October 19, 2024 17:37
Show Gist options
  • Save HeySreelal/89d8ad42599d516f4d9b9677be438234 to your computer and use it in GitHub Desktop.
Save HeySreelal/89d8ad42599d516f4d9b9677be438234 to your computer and use it in GitHub Desktop.
Pick a random member from group/channel in Telegram
from pyrogram.client import Client
import asyncio
import random
api_id = 123456 # Your Telegram API ID
api_hash = "api-hash" # Telegram API Hash
chat_id = -100123456 # Group ID/Username
app = Client("my_account", api_id, api_hash, device_model="Random Member Picker", system_version="dev/randommember")
async def main():
await app.start()
members = []
async for member in app.get_chat_members(chat_id):
members.append(member)
if members:
random_member = random.choice(members)
print(f"Randomly picked member: {random_member.user.first_name}")
if __name__ == "__main__":
print("=== Telegram Random Member Picker ===")
asyncio.run(main())
@HeySreelal
Copy link
Author

Steps:

  1. Get api_id and api_hash from https://my.telegram.org/, and replace it in respected variables
  2. Set the chat_id
  3. Make sure to install pyrogram
  4. Run python main.py

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