Shcoder001

main.py

Apr 28th, 2023
4,262
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.26 KB | None | 0 0
  1. import logging
  2. from background import keep_alive
  3. from aiogram import Bot, Dispatcher, executor, types
  4.  
  5. API_TOKEN = 'ваш токен'
  6.  
  7. # Configure logging
  8. logging.basicConfig(level=logging.INFO)
  9.  
  10. # Initialize bot and dispatcher
  11. bot = Bot(token=API_TOKEN)
  12. dp = Dispatcher(bot)
  13.  
  14.  
  15. @dp.message_handler(commands=['start', 'help'])
  16. async def send_welcome(message: types.Message):
  17.     """
  18.    This handler will be called when user sends `/start` or `/help` command
  19.    """
  20.     await message.reply("Hi!\nI'm EchoBot!\nPowered by aiogram.")
  21.  
  22.  
  23. @dp.message_handler(regexp='(^cat[s]?$|puss)')
  24. async def cats(message: types.Message):
  25.     with open('data/cats.jpg', 'rb') as photo:
  26.         '''
  27.        # Old fashioned way:
  28.        await bot.send_photo(
  29.            message.chat.id,
  30.            photo,
  31.            caption='Cats are here 😺',
  32.            reply_to_message_id=message.message_id,
  33.        )
  34.        '''
  35.  
  36.         await message.reply_photo(photo, caption='Cats are here 😺')
  37.  
  38.  
  39. @dp.message_handler()
  40. async def echo(message: types.Message):
  41.     # old style:
  42.     # await bot.send_message(message.chat.id, message.text)
  43.  
  44.     await message.answer(message.text)
  45.  
  46. keep_alive()
  47. if __name__ == '__main__':
  48.     executor.start_polling(dp, skip_updates=True)
Advertisement
Add Comment
Please, Sign In to add comment