简体   繁体   English

如何从Telegram上的群聊中获取消息?

[英]How to get messages from a group chat on Telegram?

I am having trouble understanding the Telethon API in Python. 我在理解Python中的Telethon API时遇到了麻烦。 I have created an account and have an api_id/api_hash, but I cannot connect to the server. 我已经创建了一个帐户并具有api_id / api_hash,但是我无法连接到服务器。 This is what I have: 这就是我所拥有的:

chat_id = "@thecointelegraph"
api_id = 'MYID'
api_hash = 'MYHASH'

client = TelegramClient('session_name',
                api_id,
                api_hash)
client.start()

I would like to download messages from a public telegram chat. 我想从公共电报聊天中下载消息。 Any help would be wonderful! 任何帮助都将是美好的! Thank you!! 谢谢!!

What is your current Code? 您当前的代码是什么? How do you know you can't connect to the Server? 您怎么知道您无法连接到服务器?

Usualy you would go about it kinda like this: 通常,您会像这样:

client = TelegramClient("username", "telegram_api", "api_hash")
client.start()
messages = client.get_message_history(dialog.entity, unread)

At least it was like this the last time, I used Telethon, I think by get_message_history was replaced by 至少上次是这样,我使用Telethon,我认为被get_message_history替换为

get_messages() get_messages()

https://lonamiwebs.github.io/Telethon/methods/messages/get_messages.html https://lonamiwebs.github.io/Telethon/methods/messages/get_messages.html

Best thing to do is work yourself through the documentary: https://telethon.readthedocs.io/en/stable/index.html 最好的办法是通过纪录片自己动手: https : //telethon.readthedocs.io/zh/stable/index.html

from telethon import TelegramClient

entity = 'session'  # session_name
api_id = 123456
api_hash = '56bc70000yourhash'


client = TelegramClient(entity, api_id, api_hash)
client.start()

should work 应该管用

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使用 pytelegrambotapi 在电报聊天中获取所有固定消息? - How to get all the pinned messages in a telegram chat using pytelegrambotapi? 如何使用 Telethon 获取传入电报消息的聊天或群组名称? - How to get the Chat or Group name of Incoming Telegram message using Telethon? Telegram 获取聊天消息/帖子 - python Telethon - Telegram get chat messages /posts - python Telethon 将传入消息从电报转发到另一个聊天室 - Forward incoming messages from Telegram to another chat 如何从 Telegram 获取公共频道的消息 - how to get messages of the public channels from Telegram 如何删除电报聊天中的所有消息与python - how to delete all messages in telegram chat with python 如何使用 pytelegrambotapi 在电报组中删除“新聊天成员”消息? - How can I delete 'new chat members' messages in telegram group with pytelegrambotapi? 如何将 Telegram 群聊中的照片转发到 Slack(使用 Webhooks 和 Telegram Bot)? - How to forward a photo from Telegram group chat to Slack (using Webhooks and Telegram Bot)? 使用Telegram Bot在群聊中接收服务消息 - Receiving service messages in a group chat using Telegram Bot 如何使用 Telethon 将选定人员的消息从电报组 A 转发到电报组 B - How to forward messages of selected people from telegram group A to telegram group B using telethon
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM