@deployingseverus

Почему бот не запускается?

Суть проблемы такова что, когда пытаюсь запустить код выдает ошибку которую не могу решить уже почти 2 дня, надеюсь вы мне поможете, вот код
from aiogram import Bot, Dispatcher, types
import asyncio
import requests

API_TOKEN = "********" -<b> fixed by moderator. Автор Перегенери свой токен он теперь известен всем</b>
PROBIVAPI_KEY = "YOUR_PROBIVAPI_KEY_HERE"

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

print("!BOT STARTED!")

async def get_start(message: types.Message):
    await message.answer("Hi")

async def send_welcome(message: types.Message):
    await get_start(message)

async def send_help(message: types.Message):
    await message.reply("Probiv Bot Template by DimonDev: @dimondevchat")

async def text(message: types.Message):
    nomer = message.text
    print(nomer)

    url = "https://probivapi.com/api/phone/info/" + nomer

    head = {
        "X-Auth": PROBIVAPI_KEY
    }

    response = requests.get(url, headers=head)
    print(response.text)

    try:
        json_response = response.json()
    except Exception:
        json_response = {}

    try:
        truecaller_api_name = str(json_response['truecaller']['data'][0]['name'])
    except Exception:
        truecaller_api_name = 'Not found'
    try:
        numbuster_api_name = str(json_response['numbuster']['averageProfile']['firstName']) + \
                             str(json_response['numbuster']['averageProfile']['lastName'])
    except Exception:
        numbuster_api_name = 'Not found'
    try:
        eyecon_api_name = str(json_response['eyecon'])
    except Exception:
        eyecon_api_name = 'Not found'
    try:
        viewcaller_name_list = []
        for tag in json_response['viewcaller']:
            viewcaller_name_list.append(tag['name'])
        viewcaller_api_name = ', '.join(viewcaller_name_list)
    except Exception:
        viewcaller_api_name = 'Not found'

    await message.reply(
        f" База: (Numbuster): {numbuster_api_name}\n"
        f" База: (EyeCon): {eyecon_api_name}\n"
        f" База: (ViewCaller): {viewcaller_api_name}\n"
        f" База: (TrueCaller): {truecaller_api_name}"
    )

async def main():
    await dp.start_polling()
    await bot.close()

if __name__ == '__main__':
    asyncio.run(main())


а вот собственно сама ошибка:

Traceback (most recent call last):
  File "D:\pythonPROJECTS\OSINT\maini.py", line 79, in <module>
    asyncio.run(main())
  File "C:\Users\lupa\AppData\Local\Programs\Python\Python312\Lib\asyncio\runners.py", line 194, in run
    return runner.run(main)
           ^^^^^^^^^^^^^^^^
  File "C:\Users\lupa\AppData\Local\Programs\Python\Python312\Lib\asyncio\runners.py", line 118, in run
    return self._loop.run_until_complete(task)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\lupa\AppData\Local\Programs\Python\Python312\Lib\asyncio\base_events.py", line 664, in run_until_complete
    return future.result()
           ^^^^^^^^^^^^^^^
  File "D:\pythonPROJECTS\OSINT\maini.py", line 75, in main
    await dp.start_polling()
  File "D:\pythonPROJECTS\OSINT\.venv\Lib\site-packages\aiogram\dispatcher\dispatcher.py", line 486, in start_polling
    raise ValueError("At least one bot instance is required to start polling")
ValueError: At least one bot instance is required to start polling
  • Вопрос задан
  • 234 просмотра
Пригласить эксперта
Ответы на вопрос 2
febday
@febday
Передайте экземпляр бота в start_polling
await dp.start_polling(bot)
Ответ написан
Комментировать
Kasperon27
@Kasperon27
Python, C# Developer. 5 years in coding‍
Ошибка говорит сама за себя.
Вы должны передать в функцию start_polling() экземпляр бота - bot.
await dp.start_polling(bot)
Ответ написан
Комментировать
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы