Advertisement
askanton

Пересилаємо повідомлення з #telegram у #discord | Вивчаємо #python

Mar 16th, 2023
938
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.27 KB | None | 0 0
  1. import discord
  2. from telethon import TelegramClient, events
  3. from config import tg_hash, tg_api, token
  4.  
  5. server_id = 000000000000000
  6. channel_id = 00000000000000000
  7. chats = [-1000000000000, -1000000000000000]
  8. client = TelegramClient("Test", tg_api, tg_hash)
  9.  
  10.  
  11.  
  12. async def send_message(message):
  13.     intents = discord.Intents.default()
  14.     intents.guilds = True
  15.     intents.members = False
  16.     intents.presences = False
  17.     discord_client = discord.Client(intents=intents)
  18.  
  19.     @discord_client.event
  20.     async def on_ready():
  21.         print(f'{discord_client.user} is sanding new message')
  22.         server = discord_client.get_guild(server_id)
  23.         channel = server.get_channel(channel_id)
  24.         await channel.send(message)
  25.         await discord_client.close()
  26.  
  27.     await discord_client.start(token)
  28.     print("Done")
  29.  
  30.  
  31. @client.on(events.NewMessage(chats=chats))
  32. async def handle_new_message(event):
  33.     print("Got new message")
  34.     if event.message.web_preview:
  35.         print("Web_preview")
  36.     elif event.message.photo:
  37.         print("Photo")
  38.     elif event.message.document:
  39.         print("Document")
  40.     elif event.message.text:
  41.         print("Text")
  42.         await send_message(event.message.message)
  43.  
  44.  
  45. client.start()
  46. client.run_until_disconnected()
  47.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement