gpt4 book ai didi

python - 使用 python-telegram-bot 按下开始时如何使用内联键盘发送 gif?

转载 作者:太空宇宙 更新时间:2023-11-03 21:07:14 32 4
gpt4 key购买 nike

我正在尝试制作一个菜单机器人。一切正常,但我无法在键盘和消息之前放置 GIF 进行装饰。

我使用了 .inputmedia.document 的一些变体来自here .

我什么都不懂,Python知识为零。我只能通过在互联网上阅读来即时理解。我真的不明白该怎么表达。

from telegram.ext import Updater
from telegram.ext import CommandHandler, CallbackQueryHandler
from telegram import InlineKeyboardButton, InlineKeyboardMarkup
import emoji
def start(bot, update):
update.message.reply_text(main_menu_message(),
reply_markup=main_menu_keyboard())

def main_menu(bot, update):
query = update.callback_query
bot.edit_message_text(chat_id=query.message.chat_id,
message_id=query.message.message_id,
text=main_menu_message(),
reply_markup=main_menu_keyboard())

def first_menu(bot, update):
query = update.callback_query
bot.edit_message_text(chat_id=query.message.chat_id,
message_id=query.message.message_id,
text=first_menu_message(),
reply_markup=first_menu_keyboard())

我所需要的几乎只是一个如何使用一些文本和标记键盘来表达 inputgif 命令的示例。谢谢!

最佳答案

你的意思是这样的吗?

enter image description here

如果,请继续阅读!如果没有,请在评论中告诉我。

  • 我们将使用 telegram.Bot 中的 send_animation 方法类(class)。

    Use this method to send animation files (GIF or H.264/MPEG-4 AVC video without sound).

  • 我们需要知道要发送的 GIF 的 file_id! 重要:我们需要获取the same chat with the bot中的file_id !

以下是我们如何发送带有标题内联键盘的GIF(您可以在我的GitHub上查看完整代码:wehavetogoback.py)

keyboard = [
[
InlineKeyboardButton('yes 😢', callback_data='yes'),
InlineKeyboardButton('no 😒', callback_data='no')
]
]

bot.send_animation(
chat_id=update.message.chat.id,
animation='file_id',
caption='go back??',
reply_markup=InlineKeyboardMarkup(keyboard)
)

关于python - 使用 python-telegram-bot 按下开始时如何使用内联键盘发送 gif?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55321509/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com