Почему не отправляется сообщение с встроенной кнопкой?
Aiogram
@dp.message()
async def forward_to_admin1(message: types.Message):
await bot.send_message(message.chat.id,
"text")
kb = types.InlineKeyboardButton(text="text", url='google.com')
keyboard = types.InlineKeyboardMarkup(inline_keyboard=kb)
await bot.send_message(message.chat.id, f"Пользователь {message.from_user.first_name} написал:\n\n{message.text}\n\n", reply_markup=keyboard)
inline_keyboard.0.0
Input should be a valid dictionary or instance of InlineKeyboardButton [type=model_type, input_value='text', input_type=str]
For further information visit https://errors.pydantic.dev/2.3/v/model_type
inline_keyboard.0.1
Input should be a valid dictionary or instance of InlineKeyboardButton [type=model_type, input_value='text', input_type=str]
For further information visit https://errors.pydantic.dev/2.3/v/model_type
inline_keyboard.1.0
Input should be a valid dictionary or instance of InlineKeyboardButton [type=model_type, input_value='url', input_type=str]
For further information visit https://errors.pydantic.dev/2.3/v/model_type
inline_keyboard.1.1
Input should be a valid dictionary or instance of InlineKeyboardButton [type=model_type, input_value='google.com', input_type=str]
For further information visit https://errors.pydantic.dev/2.3/v/model_type
inline_keyboard.2.0
Input should be a valid dictionary or instance of InlineKeyboardButton [type=model_type, input_value='callback_data', input_type=str]
For further information visit https://errors.pydantic.dev/2.3/v/model_type
inline_keyboard.2.1
Input should be a valid dictionary or instance of InlineKeyboardButton [type=model_type, input_value=None, input_type=NoneType]
For further information visit https://errors.pydantic.dev/2.3/v/model_type
inline_keyboard.3.0
Input should be a valid dictionary or instance of InlineKeyboardButton [type=model_type, input_value='web_app', input_type=str]
For further information visit https://errors.pydantic.dev/2.3/v/model_type
inline_keyboard.3.1
Input should be a valid dictionary or instance of InlineKeyboardButton [type=model_type, input_value=None, input_type=NoneType]
For further information visit https://errors.pydantic.dev/2.3/v/model_type
inline_keyboard.4.0
Input should be a valid dictionary or instance of InlineKeyboardButton [type=model_type, input_value='login_url', input_type=str]
For further information visit https://errors.pydantic.dev/2.3/v/model_type
inline_keyboard.4.1
Input should be a valid dictionary or instance of InlineKeyboardButton [type=model_type, input_value=None, input_type=NoneType]
For further information visit https://errors.pydantic.dev/2.3/v/model_type
inline_keyboard.5.0
Input should be a valid dictionary or instance of InlineKeyboardButton [type=model_type, input_value='switch_inline_query', input_type=str]
For further information visit https://errors.pydantic.dev/2.3/v/model_type
inline_keyboard.5.1
Input should be a valid dictionary or instance of InlineKeyboardButton [type=model_type, input_value=None, input_type=NoneType]
For further information visit https://errors.pydantic.dev/2.3/v/model_type
inline_keyboard.6.0
Input should be a valid dictionary or instance of InlineKeyboardButton [type=model_type, input_value='switch_inline_query_current_chat', input_type=str]
For further information visit https://errors.pydantic.dev/2.3/v/model_type
inline_keyboard.6.1
Input should be a valid dictionary or instance of InlineKeyboardButton [type=model_type, input_value=None, input_type=NoneType]
For further information visit https://errors.pydantic.dev/2.3/v/model_type
inline_keyboard.7.0
Input should be a valid dictionary or instance of InlineKeyboardButton [type=model_type, input_value='switch_inline_query_chosen_chat', input_type=str]
For further information visit https://errors.pydantic.dev/2.3/v/model_type
inline_keyboard.7.1
Input should be a valid dictionary or instance of InlineKeyboardButton [type=model_type, input_value=None, input_type=NoneType]
For further information visit https://errors.pydantic.dev/2.3/v/model_type
inline_keyboard.8.0
Input should be a valid dictionary or instance of InlineKeyboardButton [type=model_type, input_value='callback_game', input_type=str]
For further information visit https://errors.pydantic.dev/2.3/v/model_type
inline_keyboard.8.1
Input should be a valid dictionary or instance of InlineKeyboardButton [type=model_type, input_value=None, input_type=NoneType]
For further information visit https://errors.pydantic.dev/2.3/v/model_type
inline_keyboard.9.0
Input should be a valid dictionary or instance of InlineKeyboardButton [type=model_type, input_value='pay', input_type=str]
For further information visit https://errors.pydantic.dev/2.3/v/model_type
inline_keyboard.9.1
Input should be a valid dictionary or instance of InlineKeyboardButton [type=model_type, input_value=None, input_type=NoneType]
For further information visit https://errors.pydantic.dev/2.3/v/model_type
Я не могу понять проблему. Я пытаюсь сделать это по типу поддержки. Человек пишет запрос, администратор нажимает кнопку и отправляет сообщение пользователю. Я не понимаю, почему происходит ошибка.
Ответы (2 шт):
Как я понял у тя aiogram 3x в нём это вот так должно выглядить
@dp.message()
async def forward_to_admin1(message: types.Message):
await bot.send_message(message.chat.id,
"text")
keyboard = types.InlineKeyboardMarkup(inline_keyboard=[[
InlineKeyboardButton(text="text", url='google.com')
]])
await bot.send_message(message.chat.id, f"Пользователь {message.from_user.first_name} написал:\n\n{message.text}\n\n", reply_markup=keyboard)
у тебя не правильно клавиатура создана была прост
Приходит не то, что ожидается
По документации InlineKeyboardMarkup должен содержать список, у вас приходит строка:
class aiogram.types.inline_keyboard_markup.InlineKeyboardMarkup(*, inline_keyboard: List[List[InlineKeyboardButton]], **extra_data: Any) inline_keyboard: List[List[InlineKeyboardButton]] Array of button rows, each represented by an Array of aiogram.types.inline_keyboard_button.InlineKeyboardButton objects
Скорректировал ваш код:
@dp.message()
async def forward_to_admin1(message: types.Message):
await bot.send_message(message.chat.id,
"text")
kb = types.InlineKeyboardButton(text="text", url='google.com')
keyboard = types.InlineKeyboardMarkup(inline_keyboard=[[kb]]) #here
await bot.send_message(message.chat.id, f"Пользователь {message.from_user.first_name} написал:\n\n{message.text}\n\n", reply_markup=keyboard)