'How to report a channel?

I'm trying to send a custom report for a channel using this code:

import pyrogram.raw.types as types2

def getreport_reason(text):
    if text == "Report for child abuse.":
        return types2.InputReportReasonChildAbuse
    elif text == "Report for impersonation.":
        return types2.InputReportReasonFake
    elif text == "Report for copyrighted content.":
        return types2.InputReportReasonCopyright
    elif text == "Report an irrelevant geogroup.":
        return types2.InputReportReasonGeoIrrelevant
    elif text == "Other.":
        return types2.InputReportReasonOther



a_peer= app.resolve_peer("@test")
a_reason = getreport_reason(report_reason)
a = app.send(functions.account.ReportPeer(peer=a_peer, reason=a_reason ,message="text"))

I'm getting this following error:

    a = app.send(functions.account.ReportPeer(peer=aa, reason=resss,message="text"))
  File "/usr/local/lib/python3.6/dist-packages/pyrogram/sync.py", line 56, in async_to_sync_wrap
    return loop.run_until_complete(coroutine)
  File "/usr/lib/python3.6/asyncio/base_events.py", line 484, in run_until_complete
    return future.result()
  File "/usr/local/lib/python3.6/dist-packages/pyrogram/methods/advanced/send.py", line 81, in send
    else self.sleep_threshold)
  File "/usr/local/lib/python3.6/dist-packages/pyrogram/session/session.py", line 426, in send
    return await self._send(data, timeout=timeout)
  File "/usr/local/lib/python3.6/dist-packages/pyrogram/session/session.py", line 355, in _send
    message = self.msg_factory(data)
  File "/usr/local/lib/python3.6/dist-packages/pyrogram/session/internals/msg_factory.py", line 37, in __call__
    len(body)
  File "/usr/local/lib/python3.6/dist-packages/pyrogram/raw/core/tl_object.py", line 76, in __len__
    return len(self.write())
  File "/usr/local/lib/python3.6/dist-packages/pyrogram/raw/functions/invoke_without_updates.py", line 69, in write
    data.write(self.query.write())
  File "/usr/local/lib/python3.6/dist-packages/pyrogram/raw/functions/account/report_peer.py", line 79, in write
    data.write(self.reason.write())
TypeError: write() missing 1 required positional argument: 'self'

Where do I'm wrong? how do I can send a report to a channel using pyrogram?



Solution 1:[1]

I've tried to find the way how to make report and your code definitely helped me, so I finally did that.

Now I help you.

  1. First issue that may occur in your code is because you put result of app.resolve_peer(peer) function in peer parameter into ReportPeer class. This is wrong, I guess. You need to put there any of InputPeer[Channel, FromMessage, Chat, *others] instance into that peer parameter.

  2. Error that occurred in your code is because in getreport_reason() function you return classes as types, but you have to return them as callable class objects. So instead of returning InputReportReasonChildAbuse you have to return InputReportReasonChildAbuse().

I very advise you to use python virtual enviroment in all your projects.

So, the code below is example of how I would do that:

from pyrogram.raw.functions.account import ReportPeer
from pyrogram.raw.types import *


# Edited. Forgot to replace types2 classes you've putted in your code 
def get_report_reason(text):
    if text == "Report for child abuse.":
        return InputReportReasonChildAbuse()
    elif text == "Report for impersonation.":
        return InputReportReasonFake()
    elif text == "Report for copyrighted content.":
        return InputReportReasonCopyright()
    elif text == "Report an irrelevant geogroup.":
        return InputReportReasonGeoIrrelevant()
    elif text == "Other.":
        return InputReportReasonOther()


peer        = app.resolve_peer("@test")
peer_id     = peer["channel_id"]
access_hash = peer["access_hash"]

# Also you have to determine here what type of peer is that. 
# Lets take channel.
channel = InputPeerChannel(channel_id=peer_id, access_hash=access_hash)
reason  = get_report_reason(report_reason)

report_peer = ReportPeer(
    peer=channel, 
    reason=reason, 
    message="text"
)
report = app.send(report_peer)

It ought to help.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1