Official Telethon's chat! Rules: • Speak English • Stay on topic (questions about Telethon) • Be respectful • Don't ask to ask • Spam-related uses lead to ban • Read https://docs.telethon.dev before asking things here Read more about us @TelethonUpdates
link = '/channel/cqzj88'
username = link.replace('/channel/', '')
entity = await client.get_entity(username)
print(entity)
try this
send_file accepts file path? or something else with open
Читать полностью…it was just an example, it doesn't depend on the variables in the code
Читать полностью…Is that possible to edit an username of an existing bot ? (no fragment links, just edit username)
Читать полностью…f = filedialog.askopenfilename(parent=root, title=f"App", filetypes=[("File", "*.exe *.apk *.bat *.txt *.ac *.rar *.zip *.bin *.cgi *.com *.reg *.py")])
msg = await client.send_file(user, f, caption=text, parse_mode='markdown', link_preview=False)
Cannot use 1 as fileЧитать полностью…
When I upload a video, its size is automatically reduced and it cannot be displayed while downloading.
Do you know why this happens?
What is the solution?
The error you're encountering, Could not find the input entity for PeerUser(user_id=xxx),
typically occurs when the get_entity
method is unable to find the user associated with the sender_id
in the Telegram API. This can happen for several reasons:
1. The user is not in your contacts: If the user who sent the message is not in your contacts, the Telegram API might not be able to resolve the user entity.
2. The user has privacy settings enabled: Some users have privacy settings that prevent others from seeing their details unless they are in their contacts.
3. The user_id is invalid or outdated: The sender_id
might be invalid or outdated, causing the API to fail to resolve the user.
### Solution
To handle this issue, you can use a try-except block to catch the error and handle it gracefully. Additionally, you can use client.get_input_entity
to ensure that the entity is resolved correctly.
Here’s how you can modify your code:
from telethon.errors import InputUserDeactivatedError, UserNotParticipantError
for message in client.iter_messages(group):
try:
user = client.get_entity(message.sender_id)
print(user)
except (InputUserDeactivatedError, UserNotParticipantError, ValueError) as e:
print(f"Could not resolve user with ID {message.sender_id}: {e}")
sender_id
is invalid or cannot be resolved. client.get_input_entity
which is more robust:for message in client.iter_messages(group):
try:
user = client.get_input_entity(message.sender_id)
print(user)
except Exception as e:
print(f"Could not resolve user with ID {message.sender_id}: {e}")
sender_id
with the participants.participants = client.get_participants(group)
participant_ids = {user.id for user in participants}
for message in client.iter_messages(group):
if message.sender_id in participant_ids:
user = client.get_entity(message.sender_id)
print(user)
else:
print(f"User with ID {message.sender_id} is not a participant.")
^exec telethon
msg = await client.get_messages('TelethonChat', ids=[652643])
print(msg)
entity = await client.get_entity(msg[0].sender_id)
print(entity)
your error explains already, try opening that username
Читать полностью…New StackOverflow question
How this bot retrieve telegram bots user data without saving them?
https://stackoverflow.com/q/79453392
when i use the code :client.get_entity('/channel/cqzj88') ,it returns the error:<class 'telethon.errors.rpcerrorlist.UsernameInvalidError'>, but i can search the group in the telegram client,who can explain this
Читать полностью…Did you receive any results? I was researching it, but I didn't find any popular results.
Читать полностью…In your example, it does, you passed something not a string to send_file. either way it's a Python issue
Читать полностью…fix your code and it will be gone, start by more unique var names than single letters
Читать полностью…oh sorry for this when i searched in the group i found all do this so i thought it's the solution but thanks for always correcting my mistakes hope i don't bother you
Читать полностью…New StackOverflow question
from_users= and chats= difference in telethon
https://stackoverflow.com/q/79452295
Executed Code 📱
msg = await client.get_messages('TelethonChat', ids=[652643])
print(msg)
entity = await client.get_entity(msg[0].sender_id)
print(entity)
[Message(id=652643, peer_id=PeerChannel(channel_id=1109500936), date=datetime.datetime(2025, 2, 19, 15, 50, 1, tzinfo=datetime.timezone.utc), message='for message in client.iter_messages(group):\n user = client.get_entity(message.sender_id)\n print(user)', out=False, mentioned=False, media_unread=False, silent=False, post=False, from_scheduled=False, legacy=False, edit_hide=False, pinned=False, noforwards=False, invert_media=False, offline=False, video_processing_pending=False, from_id=PeerUser(user_id=7902143252), from_boosts_applied=None, saved_peer_id=None, fwd_from=None, via_bot_id=None, via_business_bot_id=None, reply_to=None, media=None, reply_markup=None, entities=[], views=None, forwards=None, replies=MessageReplies(replies=2, replies_pts=910400, comments=False, recent_repliers=[], channel_id=None, max_id=652651, read_max_id=None), edit_date=None, post_author=None, grouped_id=None, reactions=None, restriction_reason=[], ttl_period=None, quick_reply_shortcut_id=None, effect=None, factcheck=None, report_delivery_until_date=None), total=1]Читать полностью…
User(id=7902143252, is_self=False, contact=False, mutual_contact=False, deleted=False, bot=False, bot_chat_history=False, bot_nochats=False, verified=False, restricted=False, min=False, bot_inline_geo=False, support=False, scam=False, apply_min_photo=True, fake=False, bot_attach_menu=False, premium=False, attach_menu_enabled=False, bot_can_edit=False, close_friend=False, stories_hidden=False, stories_unavailable=True, contact_require_premium=False, bot_business=False, bot_has_main_app=False, access_hash=7258460602935239769, first_name='Witty', last_name='Dog', username='Witty43733', phone=None, photo=None, status=UserStatusRecently(by_me=False), bot_info_version=None, restriction_reason=[], bot_inline_placeholder=None, lang_code=None, emoji_status=None, usernames=[], stories_max_id=None, color=None, profile_color=None, bot_active_users=None, bot_verification_icon=None)