SilkyFalcon

Generation

typingsWed, 30 Nov 2022

from telethon import TelegramClient, events import requests import telethon import aiohttp import nextcord import textwrap import os import requests import json import random from dotenv import load_dotenv '''This will load your .env file''' load_dotenv() url = os.environ.get("WEBHOOK") appid = os.environ.get("APPID") apihash = os.environ.get("APIHASH") apiname = os.environ.get("APINAME") webhookprofile = os.environ.get("WEBHOOK_NAME") mention = os.environ.get("MENTION_ROLE_ID") input_channels_entities = os.environ.get("INPUT_CHANNELS") blacklist = os.environ.get("BLACKLIST") if blacklist == 'True': blacklist = True if input_channels_entities is not None: input_channels_entities = list(map(int, input_channels_entities.split(','))) '''Multiple channel handler''' '''This method handles Telegram events and login system''' def start(): client = TelegramClient(apiname, appid, apihash) client.start() print("[TelegramForwarder]") print(f"Input channels: {input_channels_entities}") @client.on(events.NewMessage(chats=input_channels_entities, blacklist_chats=blacklist)) async def handler(event): # Log sent messages msg = event.message.message print(f"[Visible] {msg}") standard_message_sender("<@&" + mention + ">") webhook_sender(msg) # If a message is sent by a bot it won't be forwarded by Discord. if type(event.chat) == telethon.tl.types.User: return client.run_until_disconnected() '''HTTP request-based webhook embed message sending''' def webhook_sender(message): data = {"username": webhookprofile} data["embeds"] = [ { "title": "", "description": message, "color": 16777215 }] result = requests.post(url, json=data) try: result.raise_for_status() except requests.exceptions.HTTPError as err: print(err) '''HTTP request-based webhook message sending''' def standard_message_sender(message): data = { "content" : message, "username" : webhookprofile } result = requests.post(url, json = data) try: result.raise_for_status() except requests.exceptions.HTTPError as err: print(err) '''Main method''' if __name__ == "__main__": start()

## Step 5: Running the bot Use the following command to start the bot:

Questions about programming?Chat with your personal AI assistant