Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

when I am replying to a photo I should able to get that photo#4620

Unanswered
Njking124 asked this question inQ&A
Discussion options

What kind of feature are you missing? Where do you notice a shortcoming of PTB?

I have filters.REPLY in my handler but it is not capturing when I am replying to an image. I need it capture that too

Describe the solution you'd like

give the photo in update.message.reply_to_message.photo so I can download the image

Describe alternatives you've considered

No response

Additional context

No response

You must be logged in to vote

Replies: 8 comments 1 reply

Comment options

Hi. PTB does not modify any data in theupdate, it simply wraps the data received from Telegram in Python data structures. To me this sounds like another handler might be falsely catching the update.
Please provide anMWE that shows the problem.

You must be logged in to vote
0 replies
Comment options

Hi. PTB does not modify any data in theupdate, it simply wraps the data received from Telegram in Python data structures. To me this sounds like another handler might be falsely catching the update. Please provide anMWE that shows the problem.

@Bibo-Joshi

async def handle_reply(update: Update, context: ContextTypes.DEFAULT_TYPE):    # Ensure the message is a reply    print(update.message.photo)    print(update.message.reply_to_message)    print(vars(update.message.reply_to_message))    # print(update.message.reply_to_message.photo)    # print(update.message.reply_photo)    if update.message.reply_to_message:        # Check if the replied-to message contains a photo        if update.message.reply_to_message.photo:            photo = update.message.reply_to_message.photo[-1]  # Get the highest resolution photo            file = await context.bot.get_file(photo.file_id)            await update.message.reply_text(f"You replied to a photo. File path: {file.file_path}")        else:            # Handle cases where the reply is not to a photo            await update.message.reply_text("You replied to a message, but it doesn't contain a photo.")    else:        await update.message.reply_text("This is not a reply.")def main():  app = ApplicationBuilder().token(TOKEN).build()  app.add_handler(MessageHandler(filters.REPLY, handle_reply))    app.run_polling(allowed_updates=Update.ALL_TYPES)if __name__ == "__main__":    main()

Image

You must be logged in to vote
0 replies
Comment options

Please enablelogging and/or an error handler. Then you will see the following exception:

2024-12-3012:33:05,937-telegram.ext.Application-ERROR-Noerrorhandlersareregistered,loggingexception.Traceback (mostrecentcalllast):File"path\to\python-telegram-bot\telegram\ext\_application.py",line1325,inprocess_updateawaitcoroutineFile"path\to\python-telegram-bot\telegram\ext\_handlers\basehandler.py",line158,inhandle_updatereturnawaitself.callback(update,context)^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^File"path\to\python-telegram-bot\foo.py",line21,inhandle_replyprint(vars(update.message.reply_to_message))^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^TypeError:vars()argumentmusthave__dict__attribute
You must be logged in to vote
0 replies
Comment options

import loggingfrom telegram import Updatefrom telegram.ext import (    ApplicationBuilder,    ContextTypes,    MessageHandler,    filters,)# Enable logginglogging.basicConfig(    format="%(asctime)s - %(name)s - %(levelname)s - %(message)s",     level=logging.INFO)logger = logging.getLogger(__name__)# Bot tokenTOKEN = "YOUR_BOT_TOKEN"async def handle_reply(update: Update, context: ContextTypes.DEFAULT_TYPE):    try:        # Log the incoming message details        logger.info("Received a message: %s", update.message)        logger.info("Replied-to message: %s", update.message.reply_to_message)        # Ensure the message is a reply        if update.message.reply_to_message:            # Check if the replied-to message contains a photo            if hasattr(update.message.reply_to_message, "photo") and update.message.reply_to_message.photo:                photo = update.message.reply_to_message.photo[-1]  # Get the highest resolution photo                file = await context.bot.get_file(photo.file_id)                logger.info("Photo file ID: %s", photo.file_id)                await update.message.reply_text(f"You replied to a photo. File path: {file.file_path}")            else:                # Handle cases where the reply is not to a photo                logger.warning("Replied message does not contain a photo.")                await update.message.reply_text("You replied to a message, but it doesn't contain a photo.")        else:            logger.warning("Message is not a reply.")            await update.message.reply_text("This is not a reply.")    except Exception as e:        # Log any exceptions        logger.error("Error in handle_reply: %s", e, exc_info=True)        await update.message.reply_text("An error occurred while processing your reply.")def main():    # Create the bot application    app = ApplicationBuilder().token(TOKEN).build()    # Add a handler for replies    app.add_handler(MessageHandler(filters.REPLY, handle_reply))    # Log bot startup    logger.info("Bot is starting...")    # Start the bot    app.run_polling(allowed_updates=Update.ALL_TYPES)    logger.info("Bot has stopped.")if __name__ == "__main__":    main()

@Bibo-Joshi

You must be logged in to vote
0 replies
Comment options

works for me, so I assume the issue is closed. if you're issue is not resolved, please explain what's still missing (rather than simply tagging me ;P)

You must be logged in to vote
0 replies
Comment options

is it working in group??

You must be logged in to vote
0 replies
Comment options

Please test that yourself. If you have technical questions, I'm happy to help, but you'll have to meet me half way.

PS:https://github.com/python-telegram-bot/python-telegram-bot/wiki/Ask-Right

You must be logged in to vote
0 replies
Comment options

it is working fine in dm but when replying in group it is not working can u help me brother

You must be logged in to vote
1 reply
@Bibo-Joshi
Comment options

https://github.com/python-telegram-bot/python-telegram-bot/wiki/Ask-Right

please explain it detail what exactly is not working in a group.

Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Category
Q&A
Labels
2 participants
@Njking124@Bibo-Joshi
Converted from issue

This discussion was converted from issue #4619 on December 30, 2024 11:46.


[8]ページ先頭

©2009-2025 Movatter.jp