mirror of
https://github.com/LonamiWebs/Telethon.git
synced 2024-11-28 04:13:45 +03:00
Easy method
parent
5e3af0baf0
commit
57b4f25952
|
@ -1,14 +1,12 @@
|
||||||
Messages are searched through the obvious [`SearchRequest`](https://lonamiwebs.github.io/Telethon/methods/messages/search.html), but you may run into [issues](https://github.com/LonamiWebs/Telethon/issues/215). A valid example would be:
|
Use the `search`, `filter` or `from_id` parameters in [`client.get_messages`](http://telethon.readthedocs.io/en/latest/extra/advanced-usage/accessing-the-full-api.html):
|
||||||
```python
|
```python
|
||||||
result = client(SearchRequest(
|
# 10 messages containing "hello"
|
||||||
entity, 'query', InputMessagesFilterEmpty(), None, None, 0, 0, 100
|
hello = client.get_messages(chat, 10, search='hello')
|
||||||
))
|
|
||||||
|
# 10 messages containing photos
|
||||||
|
from telethon.tl.types import InputMessagesFilterPhotos
|
||||||
|
photo = client.get_messages(chat, 10, filter=InputMessagesFilterPhotos)
|
||||||
|
|
||||||
|
# What's the total count of photos shared in this chat?
|
||||||
|
print(photo.total)
|
||||||
```
|
```
|
||||||
|
|
||||||
It's important to note that the optional parameter `from_id` has been left omitted and thus defaults to `None`. Changing it to [`InputUserEmpty`](https://lonamiwebs.github.io/Telethon/constructors/input_user_empty.html), as one could think to specify "no user", won't work because this parameter is a flag, and it being unspecified has a different meaning.
|
|
||||||
|
|
||||||
If one were to set `from_id=InputUserEmpty()`, it would filter messages from "empty" senders, which would likely match no users.
|
|
||||||
|
|
||||||
If you get a `ChatAdminRequiredError` on a channel, it's probably because you tried setting the `from_id` filter, and as the error says, you can't do that. Leave it set to `None` and it should work.
|
|
||||||
|
|
||||||
As with every method, make sure you use the right ID/hash combination for your `InputUser` or `InputChat`, or you'll likely run into errors like `UserIdInvalidError`.
|
|
Loading…
Reference in New Issue
Block a user