A
A
aikytr2021-07-18 19:21:55
Python
aikytr, 2021-07-18 19:21:55

When writing a code for a telegram bot, an error pops up. What to do?

The code:

import config
import logging

from aiogram import Bot, Dispatcher, executor, types

logging.basicCongig(level=logging.INFO)

bot = Bot(token=config.TOKEN)
dp = Dispatcher(bot)

@dp.message_handler()
async def echo(message: types.Message):
  await message.answer(message.text)


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

Mistake:
async def echo(message: types.Message):
        ^
SyntaxError: invalid syntax<

Answer the question

In order to leave comments, you need to log in

1 answer(s)
Y
Yuriy Vorobyov, 2021-07-18
@aikytr

Async was introduced starting with python 3.3, version needs to be updated
Still need to install asyncio: pip install asyncio
async/await became available starting from version 3.5, so instead of async is used @asyncio.coroutine, and instead of await -yield from

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question