1
import logging

from aiogram import Bot, Dispatcher, executor, types

API_TOKEN = '...'

# Configure logging
logging.basicConfig(level=logging.INFO)

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


@dp.message_handler(commands=['start', 'help'])
async def send_welcome(message: types.Message):
    """
    This handler will be called when user sends `/start` or `/help` command
    """
    await message.reply("Hi!\nI'm EchoBot!\nPowered by aiogram.")



@dp.message_handler()
async def echo(message: types.Message):
    print(message)
    # old style:
    # await bot.send_message(message.chat.id, message.text)

    await message.answer(message.text)

print('Bot started')

executor.start_polling(dp, skip_updates=True)

idk why my bot not working really, i'm trying to send message and without errors and did not get another indicators that something went wrong, just message in chat without reaction

Platon
  • 31
  • 2

2 Answers2

0

Most likely you lack message.from_user.id, this is why the bot does not see the input message and does not react. I suggest that your code looks the following way:

@dp.message_handler(commands=['start', 'help'])
async def send_welcome(message: types.Message):
    await bot.send_message(
        message.from_user.id, "Hi!\nI'm EchoBot!\nPowered by aiogram."
    )
Anna
  • 101
  • 8
0
if __name__ == "__main__":
    executor.start_polling(dp, skip_updates=True)

i might be wrong

lova
  • 1
  • 1
  • 1
    Remember that Stack Overflow isn't just intended to solve the immediate problem, but also to help future readers find solutions to similar problems, which requires understanding the underlying code. This is especially important for members of our community who are beginners, and not familiar with the syntax. Given that, **can you [edit] your answer to include an explanation of what you're doing** and why you believe it is the best approach? – Jeremy Caney Aug 22 '23 at 02:34