Giter VIP home page Giter VIP logo

Comments (18)

delivrance avatar delivrance commented on May 6, 2024 1

I can now see your problem.

You are logging in as Bot, right? Because this is a work in progress, you can install the latest development version: https://docs.pyrogram.ml/start/QuickInstallation#bleeding-edge,
restart your bot using this version and while is online, kick it and add it again to your channel/supergroup. Now resolve_peer with the id should work.

from pyrogram.

delivrance avatar delivrance commented on May 6, 2024 1

This is because basic groups are stored inside your account. This means that each member of a basic group have his own copy of the messages stored inside their own account (that's why you can't get old mesages in case you leave and delete the group). The method doesn't accept a chat_id for basic groups because message ids for them are shared with private messages ids.

In other words, any personal message id can be a message of either a private message or a basic group. Channels and Supergroups have their own message id space

from pyrogram.

delivrance avatar delivrance commented on May 6, 2024

@sviat9440 Hi, any bot API id starting with -100 is considered a channel or a supergroup, hence you can't use messages.GetChats, you need channels.GetChannels.

from pyrogram.

sviat9440 avatar sviat9440 commented on May 6, 2024
print(pycli.resolve_peer(1004766182)) # -1001004766182
# pyrogram.api.errors.exceptions.bad_request_400.PeerIdInvalid: [400 PEER_ID_INVALID]: The id/access_hash combination is invalid

print(pycli.resolve_peer("coding_ru"))
# {
#    "_": "types.InputPeerChannel",
#    "channel_id": 1004766182,
#    "access_hash": -8125217233421763316
# }

from pyrogram.

sviat9440 avatar sviat9440 commented on May 6, 2024

Ok, thats works. All users needs to kick and add bot again?

Then, pycli.get_messages(chat_id=pycli.resolve_peer(1004766182), message_ids=list(range(141180, 141280))) returns:
TypeError: unhashable type: 'InputPeerChannel'

from pyrogram.

delivrance avatar delivrance commented on May 6, 2024

Ok, thats works. All users needs to kick and add bot again?

No, is just the bot that wasn't aware of the channel/supergroup.

For the other errors, you are passing wrong values. Please read the docs, in particular read what kind of values you must pass: https://docs.pyrogram.ml/pyrogram/Client?highlight=get_messages#pyrogram.Client.get_messages

This is high-level convenience method, and accepts IDs as simple integers (it will automatically call resolve_peer for you). For any other raw methods not listed in the Client class you must use resolve_peer.

from pyrogram.

sviat9440 avatar sviat9440 commented on May 6, 2024

No, is just the bot that wasn't aware of the channel/supergroup.

That is, the client must always be running when you add the bot to the group?

For the other errors, you are passing wrong values.

tnx!

from pyrogram.

sviat9440 avatar sviat9440 commented on May 6, 2024

-258239875 -> simple private group

print(pycli.resolve_peer(258239875))

Traceback (most recent call last):
...
KeyError: -100258239875
...
Traceback (most recent call last):
File "test.py", line 11, in
print(pycli.resolve_peer(258239875))
File "C:\Users\sviat-pc\AppData\Local\Programs\Python\Python36\lib\site-packages\pyrogram\client\client.py", line 983, in resolve_peer
raise PeerIdInvalid
pyrogram.api.errors.exceptions.bad_request_400.PeerIdInvalid: [400 PEER_ID_INVALID]: The id/access_hash combination is invalid

from pyrogram.

delivrance avatar delivrance commented on May 6, 2024

That is, the client must always be running when you add the bot to the group?

Currently, providing you are using the latest development version, it must be online only when you are adding it again, then pyrogram will remember the id (it is stored in the session file).

-258239875 -> simple private group

I think this is just the same problem, have you kicked and added it again?

Anyway, I flagged this issue as enhancement, some code needs to be added in order to make bots be aware of groups they are part of, even without the need of kicking them.

from pyrogram.

sviat9440 avatar sviat9440 commented on May 6, 2024

I think this is just the same problem, have you kicked and added it again?

Yes. Now I use method messages.GetMessages(id), but i cant set chat_id param.
In supergroups all works. Bot not in simle groups.

from pyrogram.

sviat9440 avatar sviat9440 commented on May 6, 2024

rgr, tnx

from pyrogram.

delivrance avatar delivrance commented on May 6, 2024

To summarize: if you want messages from private chats or basic groups, you use messages.GetMessages (and pass only the message id). If you want messages from channels or supergroups, you use channels.GetMessages.

The convenience method .get_messages() is able to get messages for both entities. If you look at how's implemented you'll see that it'll use both raw functions, and will use channels.GetMessages in case the provided chat_id belongs to a channel/supergroup.

from pyrogram.

sviat9440 avatar sviat9440 commented on May 6, 2024

Anyway, I flagged this issue as enhancement, some code needs to be added in order to make bots be aware of groups they are part of, even without the need of kicking them.

Please tell when you implemented it

from pyrogram.

Pilllo avatar Pilllo commented on May 6, 2024

Kings

from pyrogram.

sviat9440 avatar sviat9440 commented on May 6, 2024

.get_messages() is able to get messages for both entities.

line 2954 client.py raise exception if I try get messages from private chats\simple groups
Then line 2963 not running

from pyrogram.

delivrance avatar delivrance commented on May 6, 2024

Please tell when you implemented it

All changes live in the github repo. For new releases I write release notes which summarize what's been changed.

line 2954 client.py raise exception if I try get messages from private chats\simple groups

Well, what exception exactly? That's important...

from pyrogram.

sviat9440 avatar sviat9440 commented on May 6, 2024

Well, what exception exactly? That's important...

Hmm, all works. Sorry. Im noob))

from pyrogram.

delivrance avatar delivrance commented on May 6, 2024

Closing. Client.get_chat has been added.

from pyrogram.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.