Skip to content

Instantly share code, notes, and snippets.

@Forevka
Created April 19, 2021 07:37
Show Gist options
  • Save Forevka/b4ab87af07ca100872036428203b10b7 to your computer and use it in GitHub Desktop.
Save Forevka/b4ab87af07ca100872036428203b10b7 to your computer and use it in GitHub Desktop.
import asyncio
import logging
import os
from aiogram import Bot, Dispatcher, executor, types
from aiogram.utils.exceptions import MessageNotModified
API_TOKEN = os.environ.get('TOKEN', '')
logging.basicConfig(level=logging.INFO)
async def send_welcome(message: types.Message):
constant_text = "Error going brrrrrrrrrrrrrr"
msg = await message.answer(constant_text)
await asyncio.sleep(1)
await msg.edit_text(constant_text)
async def throw_error(message: types.Message):
raise ValueError('test')
async def catch_not_modified(update: types.Update, error):
print('not modified', update.update_id)
return True
async def catch_all(update: types.Update, error):
print('all other', update.update_id)
return True
if __name__ == '__main__':
bot = Bot(token=API_TOKEN)
dp = Dispatcher(bot)
dp.register_message_handler(throw_error, commands=['t'])
dp.register_message_handler(send_welcome)
dp.register_errors_handler(catch_not_modified, exception=MessageNotModified)
dp.register_errors_handler(catch_all, exception=Exception)
executor.start_polling(dp, skip_updates=True)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment