mirror of
https://github.com/aiogram/aiogram.git
synced 2026-04-08 16:37:47 +00:00
update
This commit is contained in:
parent
0e2beb24c2
commit
9131ce4ac2
1 changed files with 31 additions and 0 deletions
31
examples/echo_class_based_bot_asyncio.py
Normal file
31
examples/echo_class_based_bot_asyncio.py
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
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):
|
||||
asyncio.create_task(self.dp.start_polling())
|
||||
|
||||
if __name__ == '__main__':
|
||||
bot = AsyncioBot()
|
||||
loop = asyncio.get_event_loop()
|
||||
loop.create_task(bot.run())
|
||||
|
||||
loop.run_forever()
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue