Telegram
Browse files1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950from telegram import ChatType, ParseMode, TelegramErrorfrom telegram.utils.helpers import mention_htmlfrom telegram.ext import Updaterimport logging
# Set up logginglogging.basicConfig(format='%(asctime)s - %(name)s - %(levelname)s - %(message)s', level=logging.INFO)
# Initialize the updater and botupdater = Updater(token='6558743995:AAGASl5dAQKOiOEB_MSFi4TTja-uf-xXJls', use_context=True)bot = updater.bot
def search_chats(query): results = bot.search_chats(query, limit=10) if results: for chat in results: chat_id = chat.id chat_type = chat.type chat_name = chat.title chat_link = f'https://t.me/{chat.username}' if chat.username else None
if chat_type in [ChatType.GROUP, ChatType.SUPERGROUP, ChatType.CHANNEL]: message = f'Found {chat_type} - <b>{chat_name}</b>' if chat_link: message += f' (<a href="{chat_link}">link</a>)' message += f' - ID: <code>{chat_id}</code>' print(message) else: print("No chats found for the given query.")
try: # Search chats by ID chat_id = int(input("Enter Chat ID: ")) try: chat = bot.get_chat(chat_id) search_chats(chat.title) except TelegramError: print("Invalid Chat ID.")
# Search chats by name chat_name = input("Enter Chat Name: ") search_chats(chat_name)
except ValueError: print("Invalid input. Please enter a number for Chat ID.")
# Start the scriptupdater.start_polling()updater.idle()TelegramAdded+50