I’m working on a Telegram bot using python-telegram-bot that downloads Reddit videos, processes them with moviepy, and asks users questions through a conversation flow. I’m running into two main problems:
Problem 1: Getting AttributeError: 'NoneType' object has no attribute 'reply_text' when trying to use update.message.reply_text("test")
Problem 2: The conversation handler doesn’t wait for user responses. Instead of pausing for input, it immediately moves to the next video processing cycle.
Here’s my conversation starter function:
async def begin_video_questions(update: Update, context: ContextTypes.DEFAULT_TYPE) -> int:
"""Initiates conversation by uploading video and asking first question."""
video_path = context.user_data.get('video_path')
await context.bot.send_video(chat_id=update.effective_chat.id, video=open(video_path, 'rb'))
await update.effective_message.reply_text("Which resolution do you prefer? (res1/res2)")
return RESOLUTION
My main application setup:
if __name__ == '__main__':
app = Application.builder().token('BOT_TOKEN').build()
# Handler registration
startup_handler = CommandHandler('start', startup)
app.add_handler(startup_handler)
app.add_handler(CallbackQueryHandler(callback_handler))
conversation_handler = ConversationHandler(
entry_points=[CommandHandler("start", begin_video_questions)],
states={
RESOLUTION: [MessageHandler(filters.TEXT & ~filters.COMMAND, resolution_handler)],
DURATION: [MessageHandler(filters.TEXT & ~filters.COMMAND, duration_handler)],
OVERLAY_COLOR: [MessageHandler(filters.TEXT & ~filters.COMMAND, overlay_color_handler)],
OVERLAY_ALPHA: [MessageHandler(filters.TEXT & ~filters.COMMAND, overlay_alpha_handler)],
VIDEO_TITLE: [MessageHandler(filters.TEXT & ~filters.COMMAND, video_title_handler)],
TITLE_COLOR: [MessageHandler(filters.TEXT & ~filters.COMMAND, title_color_handler)],
DESCRIPTION: [MessageHandler(filters.TEXT & ~filters.COMMAND, description_handler)],
},
fallbacks=[CommandHandler("stop", stop_conversation)],
)
app.add_handler(conversation_handler)
app.run_polling(allowed_updates=Update.ALL_TYPES)
The function that calls the conversation starter:
async def handle_reddit_videos(update: Update, context: ContextTypes.DEFAULT_TYPE, username, url, video_count):
while video_count < 3:
for clip in video_list:
await begin_video_questions(update, context)
My Questions:
- What causes the NoneType error with reply_text?
- Why does the bot skip user input and continue processing videos?
Any help would be great. Let me know if more code is needed.