I’m creating a bot that will all a certain group of users use it for sharing images to the bot.
The bot will recieve the image and forward this to a group.
I have the bot succesfully forwarding the message with the image to the group after the user confirms but I want to append the @username or userID of the person that interacted with the bot in the forwarded message.
Possibly adding a caption with the @username or @user_id of the person who submitted the post to the bot.
FILE 1
from pyrogram import (
Client,
filters
)
@Client.on_callback_query()
async def cb(client, call):
k = call.data
msgid = int(k.split("-")[1])
chat = call.message.chat.id
await call.message._client.copy_message(-100XXXXXXGROUPID, chat, msgid,
caption="")
FILE 2
Client,
filters
)
@Client.on_message(filters.private & ~filters.caption &
~filters.command("start"))
async def copy(client, message):
chat = message.chat.id
await message.copy(-100groupc)
I’ve tried adding the following to the caption:
client.get_chat_members(chat)
caption=chatmember.User
I don’t get any error but don’t get any captions.
I am a bit lost on this looking through pyrograms docs, I don’t find any good examples of how to implement something like this. I read up that the bot has to "Meet" the user first but if the user is interacting with it in the bot chat wouldn’t this work?
2
Answers
I don’t know if I already understood what are you trying to do or not but hope I got it right and here is my suggestion about the situation.
Note: You can not edit a message that is forwarded and in general, you can not edit a message that you are not sender of it.
Main Answer
I just took a look at the title you wrote and saw copy_message() function.
Actually if you take a look at the copy_message() documentation you can easily send a caption with the media you are sending.
As the documentation says:
So just write:
And boom, you are sending a caption with the media you’ve been trying to send.
Another Solution
First of all, you have to download the picture and after that you have to upload it to wherever you need.
This makes you to be the sender of the picture and after that you can edit it and add id or username of the guy to the caption. (or you can write the cation when you are uploading the picture)
But by the way if you are sure about the fact that if you forward a message from another guy to some channel you can edit that message, give it a try and comment the result down here for us but logically this should not work.
By the way, you can edit caption of an image with edit_message_caption() function and you can send a photo with send_photo() function.
Also try to take a look at the Available Methods Documentation and see which one of the function suits you
If I understood correctly, you want users to send an image to your bot, which will then be sent to a channel with a link to the original users account?
Use the bound method
message.copy()
withmessage.from_user.mention
as thecaption
.