How can I send image with spoiler in telethon? I use telethon-1.27.0.
This is the code I'm using:
client.send_message(user, file="/something.png")
I tried to use has_spoiler=True
but got an error message
send_message() got an unexpected keyword argument 'has_spoiler' or 'spoiler' and etc.
in sendmessage i found that parameter - Message sent. Return Value Message(id=123, peer_id=PeerUser(user_id=123), date=datetime.datetime(2023, 2, 5, 23, 11, 49, tzinfo=datetime.timezone.utc), message='123', out=True, mentioned=False, media_unread=False, silent=False, post=False, from_scheduled=False, legacy=False, edit_hide=False, pinned=False, noforwards=False, from_id=None, fwd_from=None, via_bot_id=None, reply_to=None, media=MessageMediaPhoto(spoiler=False, photo=Photo(id=5982148115249082446
You will need to use Telethon v1.27 or greater, and then manually construct the correct media (in this case, InputMediaUploadedPhoto
):
from telethon import TelegramClient, types
...
file = ... # path to your file 'photo.png' or file object
uploaded = await client.upload_file(file)
await client.send_file(chat, types.InputMediaUploadedPhoto(
uploaded,
spoiler=True,
))