不要发送带有内联键盘热图的消息

Dont send message with inlinekeyboard pyrogram

我尝试发送 InlineKeyboard 但捕获错误 TypeError: getattr(): attribute name must be string 代码:

    async def send_afisha_to_channel(self,about: dict) -> None:
        async with self.app:
            await self.app.send_photo(
                chat_id='@filmas_tiktok',
                photo=about['img_link'],
                caption=MessagePaterns.FILM_AFISH_PATTERN(about),
                parse_mode='html',
                reply_markup=KeyBoards.get_link_kb_pyro(about['shorturl'])
                )

Class 键盘

class KeyBoards:
    @staticmethod
    def get_link_kb_pyro(url: str, text: str = 'Смотреть') -> pyrokbmk:
        btn = pyrokbbut(text,url=url)
        kb = pyrokbmk(inline_keyboard=[btn])
        return kb

错误

Traceback (most recent call last):
  File "C:\Users\Kirill\PycharmProjects\test\venv\lib\site-packages\aiogram\dispatcher\dispatcher.py", line 415, in _process_polling_updates
    for responses in itertools.chain.from_iterable(await self.process_updates(updates, fast)):
  File "C:\Users\Kirill\PycharmProjects\test\venv\lib\site-packages\aiogram\dispatcher\dispatcher.py", line 235, in process_updates
    return await asyncio.gather(*tasks)
  File "C:\Users\Kirill\PycharmProjects\test\venv\lib\site-packages\aiogram\dispatcher\handler.py", line 116, in notify
    response = await handler_obj.handler(*args, **partial_data)
  File "C:\Users\Kirill\PycharmProjects\test\venv\lib\site-packages\aiogram\dispatcher\dispatcher.py", line 256, in process_update
    return await self.message_handlers.notify(update.message)
  File "C:\Users\Kirill\PycharmProjects\test\venv\lib\site-packages\aiogram\dispatcher\handler.py", line 116, in notify
    response = await handler_obj.handler(*args, **partial_data)
  File "c:\Users\Kirill\PycharmProjects\test\main.py", line 41, in admin_commands
    await pyroClient.send_afisha_to_channel(about=about)
  File "c:\Users\Kirill\PycharmProjects\test\contrib\utils.py", line 35, in send_afisha_to_channel
    await self.app.send_photo(
  File "C:\Users\Kirill\PycharmProjects\test\venv\lib\site-packages\pyrogram\methods\messages\send_photo.py", line 180, in send_photo
    reply_markup=await reply_markup.write(self) if reply_markup else None,
  File "C:\Users\Kirill\PycharmProjects\test\venv\lib\site-packages\pyrogram\types\bots_and_keyboards\inline_keyboard_markup.py", line 62, in write
    for b in r:
  File "C:\Users\Kirill\PycharmProjects\test\venv\lib\site-packages\pyrogram\types\object.py", line 94, in __getitem__
    return getattr(self, item)
TypeError: getattr(): attribute name must be string

键盘按钮包含 url 到按钮的站点和文本。

如果我没看错:

btn = pyrokbbut(text,url=url)
kb = pyrokbmk(inline_keyboard=[btn])

您正在定义一个按钮,并将其作为列表传递给键盘本身。 Pyrogram 及其 InlineKeyboardMarkup 需要一个列表列表,其中外部列表​​是行,内部列表是每行的按钮。

你会想要这样的东西:

keyboard = [  # List of rows:
    [button, button],  # First Row
    [button],  # Second Row
]