使用 Python 和 Telethon 库发送消息到 Telegram 群组。

from telethon import TelegramClient, events, sync

# 替换以下值为您自己的 API ID、API hash 和电话号码
api_id = 'YOUR_API_ID'
api_hash = 'YOUR_API_HASH'
phone_number = 'YOUR_PHONE_NUMBER'

# 使用以上值创建客户端对象
client = TelegramClient('session_name', api_id, api_hash)

# 启动客户端
client.start()

# 替换以下值为您要发送消息的群组 ID
group_id = 'YOUR_GROUP_ID'

# 替换以下值为您要发送的消息
message = 'Hello from Python!'

# 将消息发送到指定的群组
client.send_message(group_id, message)

# 断开客户端连接
client.disconnect()

确保将占位符值替换为您自己的 API ID、API hash、电话号码、群组 ID 和消息。

Python Telethon: 发送消息到指定群组

原文地址: https://www.cveoy.top/t/topic/lwlu 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录