telebot icon indicating copy to clipboard operation
telebot copied to clipboard

Error when adding 2 inlineKeyboard in sendGame

Open unicitee opened this issue 5 years ago • 5 comments

I would like to use 2 custom buttons for a game. With only one button, it works:

bot.on(['/start','/game'], (msg) => {
    var options = {
      replyMarkup: 
        bot.inlineKeyboard([
          [{ text: 'Some button text 1', callback_game: {} }]
        ])
      
    };
    bot.sendGame(msg.from.id, gameName, options)
});

But when I add a second button,

bot.on(['/start','/game'], (msg) => {
    var options = {
      replyMarkup: 
        bot.inlineKeyboard([
          [{ text: 'Some button text 1', callback_game: {} }],
          [{ text: 'Some button text 2', callback_game: {} }]
        ])
      
    };
    bot.sendGame(msg.from.id, gameName, options);
});

I got this error:

(node:14792) UnhandledPromiseRejectionWarning: #<Object>
(node:14792) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
(node:14792) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

unicitee avatar May 29 '20 20:05 unicitee

Hi!

Add async/await in your code and check the error.

bot.on(['/start','/game'], async (msg) => {
    var options = {
      replyMarkup: 
        bot.inlineKeyboard([
          [{ text: 'Some button text 1', callback_game: {} }],
          [{ text: 'Some button text 2', callback_game: {} }]
        ])
      
    };
    await bot.sendGame(msg.from.id, gameName, options);
});

I ran the code and get this:

[bot.error.event] { ok: false, error_code: 400, description: 'Bad Request: wrong game short name specified' }

Tell us what error you got. :D

Greetings.

rgonzlz avatar May 29 '20 22:05 rgonzlz

Hi, Thank you for your suggestion. I added async and await and I get this.

[bot.error.event] { ok: false, error_code: 400, description: 'Bad Request: BUTTON_POS_INVALID' }

The description doesn't really help. I didn't find any button pos option.

Greetings.

unicitee avatar May 30 '20 12:05 unicitee

The buttons are "special"? Like "pay", "contact" etc...

Try to change the order.

rgonzlz avatar May 30 '20 12:05 rgonzlz

The buttons are not "special". I would like to add "Play Solo" and "Play with friend" buttons. Having more than one button with sendMessage works without error. But I have trouble whith sendGame. I can't figure it out.

unicitee avatar May 30 '20 14:05 unicitee

It's simpler whith telegraf:

const Telegraf = require('telegraf')
const Extra = require('telegraf/extra')
const Markup = require('telegraf/markup')

const gameShortName = 'your-game'
const gameUrl = 'https://your-game.tld'

const markup = Extra.markup(
  Markup.inlineKeyboard([
    Markup.gameButton('Play Solo!'),
    Markup.switchToChatButton ('Play with friend!', '2')
  ])
)

const bot = new Telegraf(process.env.BOT_TOKEN)
bot.command('play', ({ replyWithGame }) => replyWithGame(gameShortName, markup))
bot.gameQuery(({ answerGameQuery }) => answerGameQuery(gameUrl))
bot.launch()

unicitee avatar May 30 '20 15:05 unicitee