Reading — step 1 of 5
Read
~1 min readBot Architecture
Event Loop & Dispatch
A bot framework provides a way to register handlers for events, then runs a loop dispatching events to handlers.
python
Async (Python's asyncio):
- Bot makes API calls (network I/O).
- Async lets handler await without blocking other handlers.
- Single event loop processes thousands of concurrent events.
Decorators:
- @bot.on('message') is syntactic sugar.
- Runtime: handlers list per event type.
Type-based routing:
- Each event has a type (message, reaction, join, leave, etc.).
- Multiple handlers per type allowed.
Filters:
- Run handler only if event matches criteria.
- E.g., only in specific channel, only from specific user.
python
Or:
python
Middleware:
- Chain of preprocessors.
- Auth check, logging, rate limit.
python
For our toy: simple decorator-based dispatch. No middleware in MVP.
Discussion
Ask a question, share an insight, or help someone who’s stuck.
Sign in to post a comment or reply.
Loading…