admin管理员组文章数量:1404927
Using iter_messages(), I scroll through messages in an open chat. If a message has reactions, I try to get the ID, name, username, and phone number (if available) of the user who reacted. In the Telegram app, this can be done by viewing the reactions and clicking on the user's profile.
However, when using Telethon, I get a ValueError. Here is part of the code:
if message.reactions and message.reactions.recent_reactions:
print(message.reactions)
peers = [reaction.peer_id for reaction in message.reactions.recent_reactions if
isinstance(reaction.peer_id, types.PeerUser)]
for peer in peers:
input_entity = await app.get_input_entity(peer) #ValueError here
user = await app.get_entity(input_entity)
user_dict = {
'first_name': user.first_name,
'last_name': user.last_name,
'username': user.username,
'phone': user.phone,
}
append_user(user.id, user_dict)
print(user.id, user_dict)
Full error message:
Unhandled exception on on_incoming_message
Traceback (most recent call last):
File "C:\Users\WWW\AppData\Local\Programs\Python\Python313\Lib\site-packages\telethon\client\updates.py", line 570, in _dispatch_update
await callback(event)
File "C:\Users\WWW\PycharmProjects\pythonPyro\Parser\main.py", line 54, in on_incoming_message
input_entity = await app.get_input_entity(peer)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\WWW\AppData\Local\Programs\Python\Python313\Lib\site-packages\telethon\client\users.py", line 469, in get_input_entity
raise ValueError(
...<4 lines>...
)
ValueError: Could not find the input entity for PeerUser(user_id=6638091654) (PeerUser).
I physically checked this message with a reaction in the chat. I can see both the message and the reaction. The user is not deleted, their account exists, and from the same account that I am using in Telethon, I can view the reacting user's profile in the Telegram app, where at least their first name (first_name) is displayed.
So what is the problem?
本文标签: pythonHow to get user details from MessageReactions in TelethonStack Overflow
版权声明:本文标题:python - How to get user details from MessageReactions in Telethon? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744869942a2629568.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论