V
V
Victor482021-05-28 22:01:25
Python
Victor48, 2021-05-28 22:01:25

How to display variable value in vk_api in pythone?

I started working with vk_api on pythone and
ran into a problem that I can not send a message with the value of a variable. The word "hello" is sent, but the value of the variable is not. Here is the code

import random
import vk_api
from vk_api.longpoll import VkLongPoll, VkEventType

session = vk_api.VkApi(token=" ")

def send_message(user_id, message,test):
session.method("messages.send", {
"user_id": user_id,
"message": message,
"test3": test3,
"random_id": 0
})

for event in VkLongPoll(session).listen():
if event.type == VkEventType.MESSAGE_NEW and event.to_me:
text = event .text.

if text == "hello":
test3 = 3

send_message(user_id, "hello",str(test3))

What is the correct way to display the value of a variable?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
St3DiTwister, 2021-05-29
@Victor48

The text of the message is taken from the "message" parameter, respectively, only what is assigned to this parameter will be sent. Therefore, "hello" and str(test3) should be combined into one variable and assigned to the "message" parameter. And the "test3" parameter is not needed, and is not defined in the method at all.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question