K
K
kirito12020-07-09 17:18:33
Python
kirito1, 2020-07-09 17:18:33

How to make a RP command in python for VK?

Hello, I want to make a RP command "hug"
Like you write in a conversation like this: "hug @id"
And the bot replies: "@your_id hugged (a) @id"

I think you understand, here is my code:

from vk_api.bot_longpoll import VkBotLongPoll, VkBotEventType
import vk_api
import time
import random
import config
 
vk = vk_api.VkApi(token="токен")
 
vk._auth_token()
 
vk.get_api()
 
longpoll = VkBotLongPoll(vk, 196622387)

password_length = 32

possible_characters = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890"
 
while True:
    for event in longpoll.listen():
        if event.type == VkBotEventType.MESSAGE_NEW:
            if event.object.peer_id != event.object.from_id:
                facts_ = random.choice(config.facts)
                if event.object.text.lower() == "Факт" or event.object.text.lower() == "факт":
                    vk.method("messages.send", {"peer_id": event.object.peer_id, "message": "А ты знал что? \n\n" + facts_,
                                                "random_id": 0})
                elif event.object.text.lower() == "Факты" or event.object.text.lower() == "факты":
                    vk.method("messages.send", {"peer_id": event.object.peer_id, "message": "А ты знал что? \n\n" + facts_,
                                                "random_id": 0})
                elif event.object.text.lower() == "Пароль" or event.object.text.lower() == "пароль":
                    random_character_list = [random.choice(possible_characters) for i in range(password_length)]
                    random_password = "".join(random_character_list)
                    password = random_password
                    vk.method("messages.send", {"peer_id": event.object.peer_id, "message": password,
                                                "random_id": 0})

                elif event.object.text.lower() == "Команды" or event.object.text.lower() == "команды":
                    vk.method("messages.send", {"peer_id": event.object.peer_id, "attachment": "wall-196622387_4" + facts_,
                                                "random_id": 0})

            elif event.object.peer_id == event.object.from_id:
                facts_ = random.choice(config.facts)
                if event.object.text.lower() == "Факт" or event.object.text.lower() == "факт":
                    vk.method("messages.send", {"user_id": event.object.from_id, "message": "А ты знал что? \n\n" + facts_,
                                                "random_id": 0})
                elif event.object.text.lower() == "Факты" or event.object.text.lower() == "факты":
                    vk.method("messages.send", {"user_id": event.object.from_id, "message": "А ты знал что? \n\n" + facts_,
                                                "random_id": 0})
                elif event.object.text.lower() == "Пароль" or event.object.text.lower() == "пароль":
                    random_character_list = [random.choice(possible_characters) for i in range(password_length)]
                    random_password = "".join(random_character_list)
                    password = random_password
                    vk.method("messages.send", {"user_id": event.object.from_id, "message": password,
                                                "random_id": 0})

                elif event.object.text.lower() == "Команды" or event.object.text.lower() == "команды":
                    vk.method("messages.send", {"user_id": event.object.peer_id, "attachment": "wall-196622387_4" + facts_,
                                                "random_id": 0})

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
sergeyfilippov4, 2020-07-09
@kirito1

if event.obj.text.split()[0] == "обнять":
    uid = event.obj.text.split()[1]
    vk.messages.send(chat_id=event.chat_id, message=f"@{event.from_id} обнял @{uid}", random_id=0)</blockquote>

S
Saraman, 2020-07-09
@Saraman

What are the troubles?
You take the id of the person who wrote and the id in the message, write a reply...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question