aiogram icon indicating copy to clipboard operation
aiogram copied to clipboard

/start doesn't work

Open sevocrear opened this issue 1 year ago • 5 comments

Checklist

  • [X] I am sure the error is coming from aiogram code
  • [X] I have searched in the issue tracker for similar bug reports, including closed ones

Operating system

Ubuntu 22.4

Python version

3.8

aiogram version

2.21

Expected behavior

Bots responds

Current behavior

/start doesn't work for the bot I made with aiogram. But for all other users it works perfectly. What could be a problem?

Steps to reproduce

  1. Open bot @WishShareBot
  2. Type /start
  3. It works (but not for me @sevocrear

Code example

No response

Logs

No logs from bot as it doesn't respond to my account

Additional information

No response

sevocrear avatar Apr 06 '24 22:04 sevocrear

As I figured out, it doesn't get messages from second account. But if I turn my script off, getUpdate (https://api.telegram.org/bot'token'/getUpdates) get all the messages I send to the bot:

{"ok":true,"result":[{"update_id":967979408, "message":{"message_id":143,"from":{"id":489327708,"is_bot":false,"first_name":"Ilia","last_name":"Sevostianov","username":"sevocrear","language_code":"ru","is_premium":true},"chat":{"id":489327708,"first_name":"Ilia","last_name":"Sevostianov","username":"sevocrear","type":"private"},"date":1712478116,"text":"For"}}]}

sevocrear avatar Apr 07 '24 08:04 sevocrear

Looks like a non-aiogram issue. Debug your application or send minimal reproducible example

Olegt0rr avatar Apr 07 '24 11:04 Olegt0rr

Have some problem now. Bot can send messages, but not handling any commands

Petrprogs avatar Apr 08 '24 07:04 Petrprogs

Have some problem now. Bot can send messages, but not handling any commands

@Petrprogs, still need minimal reproducible example

Olegt0rr avatar Apr 09 '24 04:04 Olegt0rr

Have some problem now. Bot can send messages, but not handling any commands

@Petrprogs, still need minimal reproducible example

This was problem in my code:

import asyncio
from aiogram import Bot, Dispatcher, types, F
from aiogram.filters import Command

bot = Bot(token=TG_TOKEN)
dp = Dispatcher()

@dp.message(Command("start"))
async def send_welcome(msg):
    await msg.reply("Hi there!")

async def main_loop():
    while True:
          print("Some infinty loop")
          await asyncio.sleep(10)

asyncio.run(main_loop())
asyncio.run(dp.start_polling(bot)) # This won't run, because main_loop() has infinity while loop

To solve this a just moved dp.start_polling(bot) to main_loop() like this:

import asyncio
from aiogram import Bot, Dispatcher, types, F
from aiogram.filters import Command

bot = Bot(token=TG_TOKEN)
dp = Dispatcher()

@dp.message(Command("start"))
async def send_welcome(msg):
    await msg.reply("Hi there!")

async def main_loop():
    asyncio.create_task(dp.start_polling(bot))
    while True:
          print("Some infinty loop")
          await asyncio.sleep(10)

asyncio.run(main_loop())

Sorry for my weird code :)

Petrprogs avatar Apr 09 '24 12:04 Petrprogs