如何用Python给Telegram频道帖子发反应?查Telethon API无果
使用Python给Telegram频道帖子发送反应(Telethon实现)
当然可以,用Telethon的messages.sendReaction方法就能实现,以下是具体步骤和示例:
确保Telethon版本达标:旧版本可能没封装这个方法,先执行更新:
pip install --upgrade telethon核心代码示例:
from telethon import TelegramClient from telethon.tl.types import ReactionEmoji # 替换成你的API信息和会话文件名 api_id = 123456 api_hash = 'your_api_hash_here' session_name = 'my_session' async def send_post_reaction(): async with TelegramClient(session_name, api_id, api_hash) as client: # 频道标识,可用用户名(如@my_channel)或频道ID target_channel = '@my_channel' # 帖子ID,从帖子链接(如https://t.me/my_channel/123)里提取 target_msg_id = 123 # 要发送的emoji反应 reaction = ReactionEmoji(emoji='❤️') await client.send_reaction(target_channel, target_msg_id, reaction) print("反应发送成功") if __name__ == '__main__': import asyncio asyncio.run(send_post_reaction())参数说明:
target_channel:支持频道用户名、数字ID或Telethon实体对象target_msg_id:对应帖子的消息ID,可在客户端右键帖子复制链接获取reaction:除了ReactionEmoji,还能用ReactionCustomEmoji发送自定义贴纸反应(需传入贴纸ID)
注意事项:
- 你的账号需要是频道管理员/所有者(自己的频道默认满足),拥有发送反应的权限
- 首次运行客户端需要验证手机号,后续会话文件会保存登录状态,无需重复验证
内容的提问来源于stack exchange,提问作者WA SENDER
相关产品推荐
相关产品推荐

