LonamiWebs / Telethon

Pure Python 3 MTProto API Telegram client library, for bots too!
https://docs.telethon.dev
MIT License
10.01k stars 1.41k forks source link

Messages ReportRequest InvalidPeerError #3124

Closed snip3rok closed 3 years ago

snip3rok commented 3 years ago

Code that causes the issue

from telethon.sync import TelegramClient
from telethon.tl.functions.messages import ReportRequest
from telethon.tl.types import InputReportReasonSpam

client = TelegramClient('user', ...).start()

entity = client.get_entity('username')
messages = [mes.id for mes in client.iter_messages(entity, min_id=2)]

report = client(ReportRequest(
                    peer=entity,
                    id=messages,
                    reason=InputReportReasonSpam(),
                    message='spam message'
                ))

client.disconnect()
...

Traceback

Traceback (most recent call last):
  File "/home/vkuchins/current_tg/reporter/main.py", line 39, in reports
    report = client(ReportRequest(
  File "/home/vkuchins/current_tg/reporter/venv/lib/python3.9/site-packages/telethon/sync.py", line 39, in syncified
    return loop.run_until_complete(coro)
  File "/usr/lib/python3.9/asyncio/base_events.py", line 642, in run_until_complete
    return future.result()
  File "/home/vkuchins/current_tg/reporter/venv/lib/python3.9/site-packages/telethon/client/users.py", line 30, in __call__
    return await self._call(self._sender, request, ordered=ordered)
  File "/home/vkuchins/current_tg/reporter/venv/lib/python3.9/site-packages/telethon/client/users.py", line 81, in _call
    result = await future
telethon.errors.rpcerrorlist.PeerIdInvalidError: An invalid Peer was used. Make sure to pass the right peer type and that the value is valid (for instance, bots cannot start conversations) (caused by ReportRequest)

This error from all entities type like User, InputPeerUser

Lonami commented 3 years ago

When you're using raw API, Telethon can do nothing to fix it, as the issue comes from Telegram. This belongs better in Stack Overflow https://stackoverflow.com/q/68685599.

snip3rok commented 3 years ago

On the telegram website, this method is described as messages.report # bd82b658 peer: InputPeer id: Vector reason: ReportReason = Bool; and takes 3 parameters

telethon.tl.functions.messages.ReportRequest also accepts a message .

Maybe this is the problem?

simbadmorehod commented 1 year ago

This is the kind of check that fixed the situation, I'm not a very experienced programmer and it took me 3 hours to do it

chat = await client.get_entity(int(g)) if chat.migrated_to: g = chat.migrated_to.channel_id

simbadmorehod commented 1 year ago

I get this error from time to time, it looks like my client sends to different groups

ChannelPrivateError: The channel specified is private and you lack permission to access it. Another reason may be that you were banned from it (caused by GetChannelsRequest)