Skip to content

Forwarding messages

dan levine edited this page Nov 23, 2017 · 9 revisions

Note that ForwardMessageRequest (note it's Message, singular) will not work if channels are involved. This is because channel (and megagroups) IDs are not unique, so you also need to know who the sender is (a parameter this request doesn't have).

Either way, you are encouraged to use ForwardMessagesRequest (note it's Messages, plural) always, since it is more powerful, as follows:

from telethon.tl.functions.messages import ForwardMessagesRequest
#                                             note the s ^

messages = foo()  # retrieve a few messages (or even one, in a list)
from_entity = bar()
to_entity = baz()

client(ForwardMessagesRequest(
    from_peer=from_entity,  # who sent these messages or what channel sent in?
    id=[msg.id for msg in messages],  # which are the messages?
    to_peer=to_entity  # who or what channel are we forwarding them to?
))

The named arguments are there for clarity, although they're not needed because they appear in order. You can obviously just wrap a single message on the list too, if that's all you have.