Example #1
0
from aiogram import types, Bot, Dispatcher
from aiogram.utils import executor
import config, keyboard
import time

bot = Bot(token=config.telegram_token)
dp = Dispatcher(bot)

@dp.message_handler(commands=['test'])
async def find_file_ids(message):
    for file in os.listdir('music/'):
        if file.split('.')[-1] == 'ogg':
            f = open('music/'+file, 'rb')
            msg = bot.send_voice(message.chat.id, f, None)
            # А теперь отправим вслед за файлом его file_id
            bot.send_message(message.chat.id, msg.voice.file_id, reply_to_message_id=msg.message_id)
        time.sleep(3)


if __name__ == '__main__':
    bot.polling(none_stop=True)
                                           text=FILE_ERROR_MSG,
                                           reply_markup=back_kb,
                                           disable_web_page_preview=True)
            # Проверка на неправильные команды + обработка кнопки назад в окне загрузки файла
            elif message.get('text') is not None:
                msg_text = message['text'].lower()
                if msg_text == 'назад':
                    await bot.send_message(chat_id=chat_id,
                                           text=CHOOSE_MSG,
                                           reply_markup=in_work_kb,
                                           disable_web_page_preview=True)
                    change_screen(user_id, IN_WORK_SCREEN)
                else:
                    await bot.send_message(chat_id=chat_id,
                                           text=ERROR_MSG,
                                           disable_web_page_preview=True)
            else:
                await bot.send_message(chat_id=chat_id,
                                       text=SECOND_ERROR_MSG,
                                       disable_web_page_preview=True)

        else:
            await bot.send_message(chat_id=chat_id, text=SECOND_ERROR_MSG)


"""bot.set_update_listener(handle_messages)
bot.polling(none_stop=True)"""

if __name__ == '__main__':
    executor.start_polling(dp, skip_updates=True)