skip to Main Content

I’m using pyrogram to send a html 5 game to my friends. I create a game call "popspike" from @botfather and this is the link of my html 5 game. Image below is the game example without inline button. The button is auto generated by telegram and the button is not works to launch my html 5 game.

User click the play button to start

According to discussion in stackoverflow and the documentation manual provided, we need to use callback_query.answer(url="your website") to open my html 5 game (popspike), so I create an inline button to callbakc the query data.

@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')

But I met this error when I want to call this command /popspike to send my game to user, so I failed to send the game to user.

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:Desktopcodingdiscordpyenvlibsite-packagespyrogramdispatcher.py", line 222, in handler_worker
    await handler.callback(self.client, *args)
  File "D:Desktopcodingdiscordpyenvlibsite-packagespyromodlistenlisten.py", line 93, in resolve_listener
    await self.user_callback(client, message, *args)
  File "d:Desktopcodingdiscordpytelegrammain.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:Desktopcodingdiscordpyenvlibsite-packagespyrogramtypesmessages_and_mediamessage.py", line 1633, in reply_game
    return await self._client.send_game(
  File "D:Desktopcodingdiscordpyenvlibsite-packagespyrogrammethodsbotssend_game.py", line 74, in send_game
    r = await self.send(
  File "D:Desktopcodingdiscordpyenvlibsite-packagespyrogrammethodsadvancedsend.py", line 77, in send
    r = await self.session.send(
  File "D:Desktopcodingdiscordpyenvlibsite-packagespyrogramsessionsession.py", line 362, in send
    return await self._send(data, timeout=timeout)
  File "D:Desktopcodingdiscordpyenvlibsite-packagespyrogramsessionsession.py", line 332, in _send
    RPCError.raise_it(result, type(data))
  File "D:Desktopcodingdiscordpyenvlibsite-packagespyrogramerrorsrpc_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")

I do provide InlineKeyboardButton in send_game but why Telegram says "reply markup for the game is empty" ?

I apologizes for the long question since I afraid you cant understand I want to ask.
Hope you can help me. Thank you. 🙏🏻

2

Answers


  1. As per the docs of InlineKeyboardButton

    You must use exactly one of the optional fields.

    So try removing callback_data='test' from the construction of the button.


    Edit: More precisely, send_game will automatically add such a button to your message. You only need to manually attach a keyboard, if you want more than 1 button to be appended. In this case, the first button must be the one with callback_game=CallbackGame().

    Note that for this button, callback_data is not needed to be able to parse the resulting CallbackQuery. This is because CallbackQuery.data will not be present, but CallbackQuery.game_short_name will.

    The corresponding explanations from the 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.
    Login or Signup to reply.
  2. Do this on the second paragraph:

    @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')
    

    Give the argument filters.regex('test') inside @app.on_callback_query()

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search