From their GitHub:

from aiogram import Bot, Dispatcher, executor, types


# Initialize bot and dispatcher
bot = Bot(token=API_TOKEN)
dp = Dispatcher(bot)

async def send_welcome(message: types.Message):
    This handler will be called when client send `/start` command.
    await message.reply("Hi!\nI'm EchoBot!\nPowered by aiogram.")

async def cats(message: types.Message):
    with open('data/cats.jpg', 'rb') as photo:
        await bot.send_photo(, photo, caption='Cats is here 😺',

async def echo(message: types.Message):
    await bot.send_message(, message.text)

if __name__ == '__main__':
    executor.start_polling(dp, skip_updates=True)

After rewrite:

from telethon import TelegramClient, events

# Initialize bot and... just the bot!
bot = TelegramClient('bot', 11111, 'a1b2c3d4').start(bot_token='TOKEN')

async def send_welcome(event):
    await event.reply('Howdy, how are you doing?')

async def cats(event):
    await event.reply('Cats is here 😺', file='data/cats.jpg')

async def echo_all(event):
    await event.reply(event.text)

if __name__ == '__main__':

Key differences:

  • Telethon offers convenience methods to avoid retyping bot.send_photo(, ...) all the time, and instead let you type event.reply.
  • Sending files is a lot easier. The methods for sending photos, documents, audios, etc. are all the same!

0 条评论


Avatar placeholder