python - 通过 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())
但是,似乎我找不到如何将消息发送到这些特定渠道?谁能帮我?我想向我加入的所有这些频道发送相同的消息
解决方案
推荐阅读
- java - 无法反序列化来自 kafka 主题的 json 字符串,该主题在蛇案例中具有属性
- android - 使用 react-native-firebase v6,应用程序在前台收到通知时崩溃
- c - 错误:在原始套接字中使用 sendto() 时地址错误
- swift - 如何使用完成处理程序将图像放入 SwiftUI 视图
- objective-c - 使用配置文件构建 macOS 命令行实用程序
- sequelize.js - SequelizeDatabaseError:关系“设备”不存在
- python - PEP8 的多个参数中的空格
- python - 在 python 中使用 getattr
- javascript - 如何使用 nuxt 中的函数克隆 vue 元素?
- reporting-services - 如果我们需要考虑两个参数,如何在 SSRS 中定义行数据组?