Answer the question
In order to leave comments, you need to log in
How to make a variable input to the user of a VK bot?
I want the bot to write the information that I entered in the conversation, I don’t know how to make the user enter a value into the variable.
For example, I write "!call in the bot update", and the bot "@all, listen. important information: update in the bot"
code:
import vk_api
from vk_api.bot_longpoll import VkBotLongPoll, VkBotEventType
import random
from random import randint
vk_session = vk_api.VkApi(token = "топ секрет")
longpoll = VkBotLongPoll(vk_session, 206146581)
def sender(id, text):
vk_session.method('messages.send', {'chat_id' : id, 'message' : text, 'random_id' : 0})
for event in longpoll.listen():
if event.type == VkBotEventType.MESSAGE_NEW:
if event.from_chat:
id = event.chat_id
msg = event.object.message['text'].lower()
if msg == '!призыв' or msg == '!пр':
sender(id, '@all слушайте.\nВажная информация: ' )
Answer the question
In order to leave comments, you need to log in
Usesplit
msg = event.object.message['text'].lower().split(' ')
if msg[0] in ['!призыв', '!пр']:
sender(id, f'@all слушайте.\nВажная информация: {" ".join(msg[1:])}')
As I understand it, you want to enter some information and the bot should instantly announce it to everyone. You must do:
1) Identify your message with information. By keyword and your id most likely.
2) Save this message to info variable, for example. And you can not save, but immediately pull it out.
3) Send a message to the conversation with the format string `(f"@all listen.\nImportant information: {info}")`
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question