import asyncio from telethon import TelegramClient, events, errors as telethon_errors import discord from discord import Intents import traceback # Замените на ваши данные TELEGRAM_API_ID = TELEGRAM_API_ID TELEGRAM_API_HASH = "TELEGRAM_API_HASH" DISCORD_TOKEN = "DISCORD_TOKEN_BOT" # ID каналов Discord DISCORD_CHANNEL_ALFA_ID = CHANNEL_ALFA DISCORD_CHANNEL_BETA_ID = CHANNEL_BETA async def main(): try: async with TelegramClient('my_telegram_session', TELEGRAM_API_ID, TELEGRAM_API_HASH) as telegram_client: intents = Intents.default() intents.message_content = True # Важно! Разрешает чтение содержимого сообщений async with discord.Client(intents=intents) as discord_client: try: await discord_client.wait_until_ready() print(f'Logged in as {discord_client.user}') except asyncio.CancelledError: print("Discord connection cancelled.") return @telegram_client.on(events.NewMessage(pattern=r'#alfa\s+.*')) async def handler_alfa(event): try: message = event.raw_text[5:] alfa_channel = discord_client.get_channel(DISCORD_CHANNEL_ALFA_ID) if alfa_channel: await alfa_channel.send(message) except Exception as e: print(f"Ошибка при отправке сообщения в Alfa канал: {e}") traceback.print_exc() @telegram_client.on(events.NewMessage(pattern=r'#beta\s+.*')) async def handler_beta(event): try: message = event.raw_text[5:] beta_channel = discord_client.get_channel(DISCORD_CHANNEL_BETA_ID) if beta_channel: await beta_channel.send(message) except Exception as e: print(f"Ошибка при отправке сообщения в Beta канал: {e}") traceback.print_exc() print("Telegram bot started. Waiting for messages...") await telegram_client.run_until_disconnected() except telethon_errors.SessionPasswordNeededError: print("Two-factor authentication required. Enter the code from Telegram.") except telethon_errors.rpcerrorlist.RpcError as e: print(f"Telegram API error: {e}") traceback.print_exc() except discord.errors.LoginFailure as e: print(f"Discord login failed: {e}") traceback.print_exc() except discord.errors.HTTPException as e: print(f"Discord HTTP error: {e}") traceback.print_exc() except Exception as e: print(f"An unexpected error occurred: {e}") traceback.print_exc() if __name__ == "__main__": asyncio.run(main())