You can download this code by clicking the button below.
This code is now available for download.
This function, using the Pyrogram library, retrieves a random chat photo from a private chat and sends it to the user.
Technology Stack : Pyrogram
Code Type : Chatbot function
Code Difficulty : Intermediate
def random_chat_photo(update, context):
chat = update.effective_chat
if chat.type == 'private':
with context.bot.get_chat_photo(chat.id) as photo:
context.bot.send_photo(chat.id, photo.file_id)
else:
context.bot.send_message(chat.id, "This command can only be used in private chats.")