Pyrogram:为游戏提供的回复标记为空(由 "messages.SendMedia" 引起)

Pyrogram: The provided reply markup for the game is empty (caused by "messages.SendMedia")

我正在使用 pyrogram 向我的朋友发送 html 5 游戏。我从@botfather 创建了一个名为“popspike”的游戏,这是 the link of my html 5 game。下图是没有内联按钮的游戏示例。该按钮由电报自动生成,该按钮无法启动我的 html 5 游戏。

根据discussion in Whosebug and the documentation manual provided,我们需要使用callback_query.answer(url="your website")打开我的html5游戏(popspike),所以我创建了一个内联按钮来调用查询数据。

@app.on_message(filters.command("popspike"))
async def start_command(client, message): #send game to user & inline button send callback query
    await message.reply_game('popspike'
   ,reply_markup=InlineKeyboardMarkup([[InlineKeyboardButton("Play popspike",callback_data='test',callback_game=CallbackGame())]])) #reply markup is the error
   
@app.on_callback_query()
async def openquery(client, callback_query): #show text "hello" and open my html 5 game through `url` para
    await callback_query.answer("Hello", show_alert=True, url='https://lmjaedentai.github.io/popspike')

但是当我想调用此命令/popspike将我的游戏发送给用户时遇到了这个错误,所以我未能将游戏发送给用户。

Telegram says: [400 REPLY_MARKUP_GAME_EMPTY] - The provided reply markup for the game is empty (caused by "messages.SendMedia")
Traceback (most recent call last):
  File "D:\Desktop\coding\discordpy\env\lib\site-packages\pyrogram\dispatcher.py", line 222, in handler_worker
    await handler.callback(self.client, *args)
  File "D:\Desktop\coding\discordpy\env\lib\site-packages\pyromod\listen\listen.py", line 93, in resolve_listener
    await self.user_callback(client, message, *args)
  File "d:\Desktop\coding\discordpy\telegram\main.py", line 118, in start_command
    await message.reply_game('popspike',reply_markup=InlineKeyboardMarkup([[InlineKeyboardButton("Play poxpspike",callback_data='test',callback_game=CallbackGame())]]))
  File "D:\Desktop\coding\discordpy\env\lib\site-packages\pyrogram\types\messages_and_media\message.py", line 1633, in reply_game
    return await self._client.send_game(
  File "D:\Desktop\coding\discordpy\env\lib\site-packages\pyrogram\methods\bots\send_game.py", line 74, in send_game
    r = await self.send(
  File "D:\Desktop\coding\discordpy\env\lib\site-packages\pyrogram\methods\advanced\send.py", line 77, in send
    r = await self.session.send(
  File "D:\Desktop\coding\discordpy\env\lib\site-packages\pyrogram\session\session.py", line 362, in send
    return await self._send(data, timeout=timeout)
  File "D:\Desktop\coding\discordpy\env\lib\site-packages\pyrogram\session\session.py", line 332, in _send
    RPCError.raise_it(result, type(data))
  File "D:\Desktop\coding\discordpy\env\lib\site-packages\pyrogram\errors\rpc_error.py", line 91, in raise_it
    raise getattr(
pyrogram.errors.exceptions.bad_request_400.ReplyMarkupGameEmpty: Telegram says: [400 REPLY_MARKUP_GAME_EMPTY] - The provided reply markup for the game is empty (caused by "messages.SendMedia")

我确实在 send_game 中提供了 InlineKeyboardButton,但为什么 Telegram 说“游戏的回复标记为空”?

我很抱歉问了这么长的问题,因为我怕你不明白我想问的问题。
希望你能帮助我。谢谢你。

根据the docs of InlineKeyboardButton

You must use exactly one of the optional fields.

所以尝试从按钮的构造中删除 callback_data='test'


编辑: 更准确地说,send_game 会自动在您的消息中添加这样一个按钮。如果您想要附加超过 1 个按钮,您只需要手动附加一个键盘。在这种情况下,第一个按钮必须是 callback_game=CallbackGame().

请注意,对于此按钮,callback_data 而不是 才能解析生成的 CallbackQuery。这是因为 CallbackQuery.data 不会出现,但 CallbackQuery.game_short_name 会出现。

对应的解释来自official Telegram docs

  • If you send the game message without any buttons, it will automatically have a 'Play GameName' button. When this button is pressed, your bot gets a CallbackQuery with the game_short_name of the requested game. You provide the correct URL for this particular user and the app opens the game in the in-app browser.
  • You can manually add multiple buttons to your game message. Please note that the first button in the first row must always launch the game, using the field callback_game in InlineKeyboardButton. You can add extra buttons according to taste: e.g., for a description of the rules, or to open the game's official community.

在第二段执行此操作:

@app.on_callback_query(filters.regex('test'))
async def openquery(client, callback_query): #show text "hello" and open my html 5 game through `url` para
    await callback_query.answer("Hello", show_alert=True, url='https://lmjaedentai.github.io/popspike')

@app.on_callback_query()

中给出参数filters.regex('test')