skip to Main Content
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

2

Answers


  1. 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."
        )
    
    Login or Signup to reply.
  2. if __name__ == "__main__":
        executor.start_polling(dp, skip_updates=True)
    

    i might be wrong

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search