bot.send_media_group 失败(python-telegram-bot)
我需要一个用于机器人的处理程序,该处理程序将拍摄一组照片和视频,并将它们与文本一起发送给该组。 下面的代码仅发送分开的消息:
def photo(update: Update, context: CallbackContext) -> None:
global fwd_chat_id
context.bot.send_media_group(chat_id=fwd_chat_id,
media=[InputMediaPhoto(media=update.message.photo[0].file_id)])
photo_handler = MessageHandler(Filters.photo | Filters.video, photo)
dispatcher.add_handler(photo_handler)
但是,如果我尝试先收集所有照片,然后将它们发送给所有我收到的“ telegram.error.badrequest:消息文本为空”
def photo(update: Update, context: CallbackContext) -> None:
global fwd_chat_id, media_group
if media_group == []:
media_group.append(InputMediaPhoto(media=update.message.photo[0].file_id, caption='1'))
else:
media_group.append(InputMediaPhoto(media=update.message.photo[0].file_id))
photo_handler = MessageHandler(Filters.photo | Filters.video, photo)
dispatcher.add_handler(photo_handler)
def finish_photo_loading(update: Update, context: CallbackContext) -> None:
global fwd_chat_id, media_group
context.bot.send_media_group(chat_id=fwd_chat_id,
media=media_group)
finish_handler = CommandHandler('finish', finish_photo_loading)
dispatcher.add_handler(finish_handler)
I need a handler for bot that will take a group of photos and videos, and will send them in one message along with the text to the group.
The code below sends only separated messages:
def photo(update: Update, context: CallbackContext) -> None:
global fwd_chat_id
context.bot.send_media_group(chat_id=fwd_chat_id,
media=[InputMediaPhoto(media=update.message.photo[0].file_id)])
photo_handler = MessageHandler(Filters.photo | Filters.video, photo)
dispatcher.add_handler(photo_handler)
But if I try to collect all photos first and then send them all I get "telegram.error.BadRequest: Message text is empty"
def photo(update: Update, context: CallbackContext) -> None:
global fwd_chat_id, media_group
if media_group == []:
media_group.append(InputMediaPhoto(media=update.message.photo[0].file_id, caption='1'))
else:
media_group.append(InputMediaPhoto(media=update.message.photo[0].file_id))
photo_handler = MessageHandler(Filters.photo | Filters.video, photo)
dispatcher.add_handler(photo_handler)
def finish_photo_loading(update: Update, context: CallbackContext) -> None:
global fwd_chat_id, media_group
context.bot.send_media_group(chat_id=fwd_chat_id,
media=media_group)
finish_handler = CommandHandler('finish', finish_photo_loading)
dispatcher.add_handler(finish_handler)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
因此,我的解决方案是与以下方式收集所有打磨照片:
然后使用send_media_group:
获得命令/finish 之后
So my solution is to collect all sanded photos with:
And then use send_media_group:
after getting command /finish