Closed gurland closed 7 years ago
Documentation says that from_id supports InputUserSelf constructor
Yeah, an instance.
You're passing the class, InputMessagesFilterEmpty
and InputUserSelf
itself, not an instance (in Python, you would do InputMessagesFilterEmpty()
and InputUserSelf()
).
So what else need to be done to call that method?
dialogs, entities = client.get_dialogs(10)
entity = entities[0]
me = InputUserSelf()
filter = InputMessagesFilterEmpty()
result = client(SearchRequest(
entity,
q='',
filter=filter,
min_date=0,
max_date=0,
offset=0,
max_id=0,
limit=10,
from_id=me
))
Traceback (most recent call last):
File "<stdin>", line 10, in <module>
File "C:\Users\*\Desktop\Telethon-master\telethon\telegram_client.py", line 199, in invoke
request, updates=updates
File "C:\Users\*\Desktop\Telethon-master\telethon\telegram_bare_client.py", line 283, in invoke
self._sender.send(request)
File "C:\Users\*\Desktop\Telethon-master\telethon\network\mtproto_sender.py", line 60, in send
request.on_send(writer)
File "C:\Users\*\Desktop\Telethon-master\telethon\tl\functions\messages\search.py", line 68, in on_send
writer.tgwrite_date(self.min_date)
File "C:\Users\*\Desktop\Telethon-master\telethon\extensions\binary_writer.py", line 100, in tgwrite_date
value = 0 if datetime is None else int(datetime.timestamp())
AttributeError: 'int' object has no attribute 'timestamp'
min_date
should be a date
, not an integer. You can leave it as None
. Under the hood, they are indeed timestamps but working with Python's date
object is more comfortable.
OK cool, I got it working (example for whoever reads this page:)
search = 'hello'
chat = InputPeerChannel(id, access_hash)
filter = InputMessagesFilterEmpty()
result = client(SearchRequest(
chat,
q=search,
filter=filter,
min_date=None,
max_date=None,
offset=0,
max_id=0,
limit=1,
from_id=InputUserEmpty()
))
But why can't I search in supergroups? When assigning ID and ACCESS_HASH of a supergroup I get the following error:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Program Files (x86)\Python36-32\lib\site-packages\telethon\telegram_client.py", line 205, in invoke
request, updates=updates
File "C:\Program Files (x86)\Python36-32\lib\site-packages\telethon\telegram_bare_client.py", line 276, in invoke
self._sender.receive(request, updates=updates)
File "C:\Program Files (x86)\Python36-32\lib\site-packages\telethon\network\mtproto_sender.py", line 109, in receive
remote_msg_id, remote_seq, reader, updates)
File "C:\Program Files (x86)\Python36-32\lib\site-packages\telethon\network\mtproto_sender.py", line 207, in _process_msg
return self._handle_rpc_result(msg_id, sequence, reader)
File "C:\Program Files (x86)\Python36-32\lib\site-packages\telethon\network\mtproto_sender.py", line 355, in _handle_rpc_result
raise error
telethon.errors.rpc_errors_400.ChatAdminRequiredError: (ChatAdminRequiredError(...), 'Chat admin privileges are required to do that in the specified chat (for example, to send a message in a channel which is not yours).')
(when I make a search from the app \ web client it works) Any Idea?
EDIT: Just found out SearchGlobalRequest helps! EDIT # 2 this method returns results from all chats..? this is confuzing is there a way to get search results from only one group which is also a supergroup?
Code snippet:
And traceback:
Documentation says that from_id supports InputUserSelf constructor