skip to Main Content

So, im trying to create a button that will redirect me to one of my other bots.

Not really sure how to do that.

for now, this is the sample, this does add the button, but it just echos, instead of actually doing something.

from aiogram.types import ReplyKeyboardMarkup, KeyboardButton, InlineKeyboardButton

studyboi = InlineKeyboardButton('https://t.me/studyboiibot', url='https://t.me/studyboiibot')
start_keyboard = ReplyKeyboardMarkup(resize_keyboard=True).add(studyboi)

This is the documentation page – https://aiogram.2038.io/api/types/inline_keyboard_button/

Not sure what I’m doing wrong.

3

Answers


  1. You have to use InlineKeyboardMarkup for InlinekeyboardButtons.

    Buttons should be in the format of List[List[InlineKeyboardButton]]

    ReplyKeyboardMarkup replaces the client-side keyboard, whereas InlineKeyboardMarkup adds buttons in the message

    InlineKeyboardMarkup is to InlineKeyboardButton,
    ReplyKeyboardMarkup is to KeyboardButton

    Login or Signup to reply.
  2. Try this:

    keyboard = InlineKeyboardMarkup()
    button = InlineKeyboardButton('text', url='https://t.me/studyboiibot')
    keyboard.add(button)
    
    Login or Signup to reply.
  3. You can use my template. In this piece of code, I am creating two buttons. In the first one, you just go to another bot, pass the link in the implementation of the handler. And the second button is cancel, for it you will also need to create a separate handler

    choice = InlineKeyboardMarkup(row_width=2,
                                  inline_keyboard=[
                                      [
                                          InlineKeyboardButton(
                                              text="Go to another bot",
                                          )
                                      ],
                                      [
                                          InlineKeyboardButton(
                                              text="Cancel",
                                              callback_data="cancel"
                                          )
                                      ]
                                  ])
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search