I’m developing a Telegram bot using the python-telegram-bot library. The bot is supposed to forward GIFs and videos to another user without watermarking the original sender’s ID. While send_animation works perfectly, send_video fails to send the video. Here’s the relevant part of my code:
<code>def forward_media(update: Update, context: CallbackContext):
message = update.message
bot = context.bot
chat_id = TARGET_USER_ID
try:
if message.animation:
bot.send_animation(chat_id=chat_id, animation=message.animation.file_id,
caption=message.caption, parse_mode=ParseMode.HTML)
update.message.reply_text("GIF has been forwarded successfully.")
elif message.video:
bot.send_video(chat_id=chat_id, video=message.video.file_id,
caption=message.caption, parse_mode=ParseMode.HTML)
update.message.reply_text("Video has been forwarded successfully.")
else:
update.message.reply_text("Please send a GIF or video.")
except Exception as e:
logging.error(f"Error occurred: {e}")
update.message.reply_text("An error occurred while forwarding the media. Please try again.")
</code>
<code>def forward_media(update: Update, context: CallbackContext):
message = update.message
bot = context.bot
chat_id = TARGET_USER_ID
try:
if message.animation:
bot.send_animation(chat_id=chat_id, animation=message.animation.file_id,
caption=message.caption, parse_mode=ParseMode.HTML)
update.message.reply_text("GIF has been forwarded successfully.")
elif message.video:
bot.send_video(chat_id=chat_id, video=message.video.file_id,
caption=message.caption, parse_mode=ParseMode.HTML)
update.message.reply_text("Video has been forwarded successfully.")
else:
update.message.reply_text("Please send a GIF or video.")
except Exception as e:
logging.error(f"Error occurred: {e}")
update.message.reply_text("An error occurred while forwarding the media. Please try again.")
</code>
def forward_media(update: Update, context: CallbackContext):
message = update.message
bot = context.bot
chat_id = TARGET_USER_ID
try:
if message.animation:
bot.send_animation(chat_id=chat_id, animation=message.animation.file_id,
caption=message.caption, parse_mode=ParseMode.HTML)
update.message.reply_text("GIF has been forwarded successfully.")
elif message.video:
bot.send_video(chat_id=chat_id, video=message.video.file_id,
caption=message.caption, parse_mode=ParseMode.HTML)
update.message.reply_text("Video has been forwarded successfully.")
else:
update.message.reply_text("Please send a GIF or video.")
except Exception as e:
logging.error(f"Error occurred: {e}")
update.message.reply_text("An error occurred while forwarding the media. Please try again.")
TL;DR: send_video in python-telegram-bot fails to send videos (doesn’t do anything with no errors) while send_animation works fine for GIFs. Why might this be happening, and how can I fix it?