Migrating from dumbot

Showcasing their subclassing example:

from dumbot import Bot

class Subbot(Bot):
    async def init(self):
        self.me = await self.getMe()

    async def on_update(self, update):
        await self.sendMessage(
            text='i am {}'.format(self.me.username)


After rewriting:

from telethon import TelegramClient, events

class Subbot(TelegramClient):
    def __init__(self, *a, **kw):
        await super().__init__(*a, **kw)
        self.add_event_handler(self.on_update, events.NewMessage)

    async def connect():
        await super().connect()
        self.me = await self.get_me()

    async def on_update(event):
        await event.reply('i am {}'.format(self.me.username))

bot = Subbot('bot', 11111, 'a1b2c3d4').start(bot_token='TOKEN')

Key differences:

  • Telethon method names are snake_case.
  • dumbot does not offer friendly methods like update.reply.
  • Telethon does not have an implicit on_update handler, so we need to manually register one.