首页 > 解决方案 > 通过 API 从我的个人电报帐户发送消息

问题描述

我有这个代码可以登录我的帐户并从列表中加入频道:

from telethon.sync import TelegramClient
from telethon.tl.functions.channels import JoinChannelRequest
from telethon.errors.rpcerrorlist import FloodWaitError

from dotenv import load_dotenv
import os
import asyncio

load_dotenv()
API_ID = os.getenv('API_ID')
API_HASH = os.getenv('API_HASH')


CHANNELS = ['techngames']  # the channels you want to join


async def main():
    async with TelegramClient('tg_session', API_ID, API_HASH) as client:
        for channel in CHANNELS:
            try:
                await client(JoinChannelRequest(channel))
            except FloodWaitError as fwe:
                print(f'Waiting for {fwe}')
                await asyncio.sleep(delay=fwe.seconds)


asyncio.run(main())

但是,似乎我找不到如何将消息发送到这些特定渠道?谁能帮我?我想向我加入的所有这些频道发送相同的消息

标签: pythontelegram

解决方案


推荐阅读