когда пытаюсь запустить код:
from aiogram import Bot, Dispatcher, types
import asyncio
import requests
PROBIVAPI_KEY = "YOUR_PROBIVAPI_KEY_HERE"
bot = Bot(token="7161414575:AA***4oG_gpEDzcHA1aT0fZQ")
dp = Dispatcher()
print("!BOT STARTED!")
async def get_start(message: types.Message):
await message.answer("Hi")
async def send_welcome(message: types.Message):
"""
This handler will be called when user sends `/start` command
"""
await get_start(message)
async def send_help(message: types.Message):
"""
This handler will be called when user sends `/help` command
"""
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()
dp.register_message_handler(get_start())
dp.register_message_handler(send_welcome())
dp.register_message_handler(send_help())
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
wchistow
4,1297 золотых знаков16 серебряных знаков34 бронзовых знака
1 ответ 1
При создании dp передайте в класс Dispatcher bot:
dp = Dispatcher(bot)
# +++
ответ дан 2 мар. 2024 в 16:58
wchistow
4,1297 золотых знаков16 серебряных знаков34 бронзовых знака
Начните задавать вопросы и получать на них ответы
Найдите ответ на свой вопрос, задав его.
Задать вопросlang-py