I've been looking in the documentation and couldn't find why this is so.
If I get the message.id from a NewMessage
event I get a 4-digit code but if I use a userbot and call client.iter_messages
the messages come out with a 6-digit id.
I have a bot that saves message information (id included) in a database and that it returns different ids is causing me problems.
What am I missing?
Edit:
I thought it was not a bug and was asking why it was like that but they ask me to edit the question with code. So that tells me that it shouldn't happen.
import os
from telethon import TelegramClient, events
from telethon.sessions import StringSession
api_id = os.environ['TELEGRAM_API_ID']
api_hash = os.environ['TELEGRAM_API_HASH']
normal_bot_client = TelegramClient(StringSession(os.environ['TELEGRAM_BOT_SESSION']), api_id, api_hash)
user_bot_client = TelegramClient(StringSession(os.environ['TELEGRAM_USER_SESSION']), api_id, api_hash)
@normal_bot_client.on(events.NewMessage)
async def handler(event):
print(f'{event.message.id=}')
print(f'{event.message.text=}')
print('-----------------')
async with user_bot_client:
normal_bot_user = await normal_bot_client.get_me()
async for message in user_bot_client.iter_messages(normal_bot_user.username, 3): # private chat with the bot
print(f'{message.id=}')
print(f'{message.text=}')
print()
with normal_bot_client:
normal_bot_client.run_until_disconnected()
Output:
event.message.id=5271
event.message.text='bye'
-----------------
message.id=422145
message.text='bye'
message.id=422144
message.text='hi'
message.id=422143
message.text='hello'
On the other hand, I just ran into this:
normal_bot_user = await normal_bot_client.get_me()
something = await user_bot_client.get_input_entity(normal_bot_user)
print(something)
something = await user_bot_client.get_input_entity(normal_bot_user.username)
print(something)
Output:
InputPeerSelf()
InputPeerUser(user_id=545165****, access_hash=-728710854129895****)
get_input_entity
returns something different depending on whether it reads the entire User
object or just the name. If I pass him another bot, it seems that he doesn't even look at it and says that it's himself.