Андрей Сахаров
Ученик
(71),
на голосовании
2 недели назад
Учусь делать ботов в ВК, пытался сделать чтобы отвечал на сообщение в итоге выдает эту ошибку Traceback (most recent call last): File "/data/user/0/ru.iiec.pydroid3/files/accomp_files/iiec_run/iiec_run.py", line 31, in <module> start(fakepyfile,mainpyfile) File "/data/user/0/ru.iiec.pydroid3/files/accomp_files/iiec_run/iiec_run.py", line 30, in start exec(open(mainpyfile).read(), __main__.__dict__) File "<string>", line 16, in <module> File "<string>", line 5, in write_message File "/data/user/0/ru.iiec.pydroid3/files/aarch64-linux-android/lib/python3.11/site-packages/vk_api/vk_api.py", line 697, in method raise error vk_api.exceptions.ApiError: [3] Unknown method passed
[Program finished] Вот код import vk_api from vk_api.longpoll import VkLongPoll, VkEventType from vk_api.utils import get_random_id def write_message(sender, message): authorize.method('messages_send', {'user_id': sender, 'message': message, "random_id": get_random_id()}) token = "токен" authorize = vk_api.VkApi(token = token) longpoll = VkLongPoll(authorize) for event in longpoll.listen(): if event.type == VkEventType.MESSAGE_NEW and event.to_me and event.text: new_msg = event.text sender = event.user_id if new_msg == "привет": write_message(sender, "добрый день") else: write_message(sender, "я вас не понимаю")
Traceback (most recent call last):
File "/data/user/0/ru.iiec.pydroid3/files/accomp_files/iiec_run/iiec_run.py", line 31, in <module>
start(fakepyfile,mainpyfile)
File "/data/user/0/ru.iiec.pydroid3/files/accomp_files/iiec_run/iiec_run.py", line 30, in start
exec(open(mainpyfile).read(), __main__.__dict__)
File "<string>", line 16, in <module>
File "<string>", line 5, in write_message
File "/data/user/0/ru.iiec.pydroid3/files/aarch64-linux-android/lib/python3.11/site-packages/vk_api/vk_api.py", line 697, in method
raise error
vk_api.exceptions.ApiError: [3] Unknown method passed
[Program finished]
Вот код
import vk_api
from vk_api.longpoll import VkLongPoll, VkEventType
from vk_api.utils import get_random_id
def write_message(sender, message):
authorize.method('messages_send', {'user_id': sender, 'message': message, "random_id": get_random_id()})
token = "токен"
authorize = vk_api.VkApi(token = token)
longpoll = VkLongPoll(authorize)
for event in longpoll.listen():
if event.type == VkEventType.MESSAGE_NEW and event.to_me and event.text:
new_msg = event.text
sender = event.user_id
if new_msg == "привет":
write_message(sender, "добрый день")
else:
write_message(sender, "я вас не понимаю")