Answer the question
In order to leave comments, you need to log in
Why is the bot installed on the server sending a long message?
Faced the problem of delaying the sending message of the bot installed on the server. The bot is written on the aiogram library to work with the database using gino, there is the following piece of code:
@dp.callback_query_handler(lambda c: c.data and c.data.startswith('bet-list'))
async def bet_list_page_handler(callback_query: types.CallbackQuery):
chat_id = callback_query.message.chat.id
page_number = int(callback_query.data.split('-')[-1])
chat = await Chat.query.where(Chat.chat_id == chat_id).gino.first()
###
now = datetime.utcnow()
###
if chat is not None:
await bot.delete_message(chat_id, callback_query.message.message_id)
rnd = await Round.query.where(Round.chat_id == chat.id).gino.first()
if rnd is None:
msg = '♂️ Раунд еще не начался!'
keyboard = None
else:
players = await Player.query.where(Player.p_round == rnd.id).gino.all()
prev_page, next_page, players = await get_players_page(players, page_number)
if not players:
msg = ' Ставок еще нет!'
keyboard = None
m = await bot.send_message(chat_id)
await Message.create(message_id=m.message_id,
chat_id=chat.id, m_type='LIST')
else:
msg = ' Список ставок:\n\n'
for i, player in enumerate(players, start=(10 * page_number) - 9):
user = await User.get(player.user)
msg += f'{i}. @{user.username} - <b>${player.rate}</b>\n'
keyboard = await keyboard_list(prev_page, next_page, page_number)
await send_message(chat_id, chat.id, msg, 'LIST', reply_markup=keyboard)
###
print((datetime.utcnow() - now).seconds, 'seconds')
###
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question