N
N
Nikitumbapunk2282021-06-09 11:36:27
Bots
Nikitumbapunk228, 2021-06-09 11:36:27

How to fix vk api error?

writes the following error Traceback (most recent call last):
File "/home/aboaus/bot/bot", line 3, in
import vk_api
ModuleNotFoundError: No module named 'vk_api'
Here is the code if that
import random

import vk_api
from vk_api.longpoll import VkLongPoll, VkEventType

from commander.commander import Commander

def write_msg(user_id, message):
vk.method('messages.send', {'user_id': user_id, 'message': message, 'random_id': random.randint(0, 2048)})

# API key created earlier
token = "Your API token here..."

# Authorize as community
vk = vk_api.VkApi(token=token)

# Working with messages
longpoll = VkLongPoll(vk)

# Commander
commander = Commander()

print("Bot is running")
# Main loop
for event in longpoll.listen():

# If a new message has arrived
if event.type == VkEventType.MESSAGE_NEW:

# If it has a label for me( then there is a bot)
if event.to_me:

# Message from the user
request = event.text

# Stone response logic
if request == "hello":
write_msg(event.user_id, "Hi")
elif request == "bye":
write_msg(event .user_id, "Bye((")
elif request.split()[0] == "command":
write_msg(event.user_id, commander.do(request[8::]))
else:
write_msg(event.user_id, "I didn't understand your answer...")
The script is hosted by pythonanywhere if anything.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
K
Kentavr16, 2021-06-09
@Kentavr16

Most likely the module is simply not installed. Look at the documentation - most likely you need to install it by typing pop install vk in the server console

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question