@dp.message_handler(commands=['menu'])
async def menu(message: types.Message):
if message.from_user.username in listOfAdmins:
buttons = [
types.InlineKeyboardButton(text="Изменить значение текста", callback_data = 'change'),
types.InlineKeyboardButton(text="Отправить текст", callback_data = 'send')
]
keyboard = types.InlineKeyboardMarkup(row_width=1)
keyboard.add(*buttons)
file = openTextToRead()
await bot.send_message(message.from_user.id,f'Привет, @{message.from_user.username}!\nТекущее сообщение: <b>{file.read()}</b>\n Меню:', parse_mode='html', reply_markup=keyboard)
@dp.callback_query_handler(text="change")
async def changingText(call: types.CallbackQuery):
if call.from_user.username in listOfAdmins:
await call.message.answer('Отправь текст который будет рассылаться(старый сотрётся если был).')
await WritingText.enter_text.set()
await call.answer()
@dp.message_handler(state=WritingText.enter_text)
async def writeText(message: types.Message, state: FSMContext):
file = openTextToWrite()
await state.update_data(text=message.text)
text = await state.get_data()
file.write(text['text'])
await state.finish()
file.close()
await message.answer('Успешно!')
await menu(message)
@dp.callback_query_handler(text="send")
async def sendingText(call: types.CallbackQuery):
if call.from_user.username in listOfAdmins:
file = openTextToRead()
await bot.send_message(GROUP_ID, file.read())
await call.message.answer('Успешно!')
await call.answer()
file.close()
await menu(call.message) # Нужно вызвать здесь. в этом коде ничего не выводит, но и ошибок нет
if __name__ == '__main__':
executor.start_polling(dp, skip_updates=True)