aiogram/examples/echo_class_based_bot_asyncio.py

28 lines
660 B
Python
Raw Normal View History

2022-04-22 16:45:16 +10:00
from aiogram import Bot, Dispatcher, types
import logging
import asyncio
API_TOKEN = "<TOKEN>"
logging.basicConfig(level=logging.INFO)
class AsyncioBot:
# Initialize bot and dispatcher
def __init__(self) -> None:
self.bot = Bot(token=API_TOKEN)
self.dp = Dispatcher(self.bot)
self.dp.register_message_handler(self.on_message)
async def on_message(self, message: types.Message):
print(message.get_command())
await message.answer(f"Asnwer: {message.text}")
async def run(self):
2022-05-13 16:39:48 +10:00
await self.dp.start_polling()
2022-04-22 16:45:16 +10:00
if __name__ == '__main__':
bot = AsyncioBot()
2022-05-13 16:39:48 +10:00
asyncio.run(bot.run())
2022-04-22 16:45:16 +10:00